how do i find the min value using for loop?

2 views (last 30 days)
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)

Accepted Answer

Chunru
Chunru on 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 Comments
Chunru
Chunru on 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.

Sign in to comment.

More Answers (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!