how do i find the min value using for loop?

3 Ansichten (letzte 30 Tage)
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)

Akzeptierte Antwort

Chunru
Chunru am 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 Kommentare
Chunru
Chunru am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (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