how do i find the min value using for loop?

1 visualizzazione (ultimi 30 giorni)
clc
clear all
syms x
for yr = linspace(0,1,10)
f = sin(x);
fL = [0 pi];
iL = [0 pi];
Volume = pi*int((f-yr)^2,iL(1),iL(2));
s=double(Volume)
end
h=min(s)

Risposta accettata

Chunru
Chunru il 28 Nov 2021
syms x
smin = inf; % initialize smin
for yr = linspace(0,1,10)
f = sin(x);
fL = [0 pi];
iL = [0 pi];
Volume = pi*int((f-yr)^2,iL(1),iL(2));
s=double(Volume);
if s<smin,
smin = s;
end
end
%h=min(s)
smin
smin = 0.9437
  8 Commenti
Chunru
Chunru il 29 Nov 2021
syms x
smin = inf; % initialize smin
locmin = nan;
for yr = linspace(0,1,10)
f = sin(x);
fL = [0 pi];
iL = [0 pi];
Volume = pi*int((f-yr)^2,iL(1),iL(2));
s=double(Volume);
if s<smin,
smin = s;
locmin = yr;
end
end
smin, yr
smin = 0.9437
yr = 1
lakshmi sampath reddy Pulagum
ahh it is wrong.its taking yr=1 for max and min too.can you please check it.

Accedi per commentare.

Più risposte (1)

lakshmi sampath reddy Pulagum
thank you soo much.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by