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)

 채택된 답변

Chunru
Chunru 2021년 11월 28일
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

I could not understand it why have you choosen infinity as smin? Can you please explain?
Chunru
Chunru 2021년 11월 28일
편집: Chunru 2021년 11월 28일
You put a very large value as the initial value to ensure that the min is from the data. You can go through a simple example of s = -10, -100, 200, 1000 and examine what happens with:
smin = inf
for s = [-10, -100, 200, 1000]
if s<smin,
smin = s;
end
end
thank you so much.now i could understand it.its a good logic.once again thank you.
and how can i find the point at which it is minimum
clc
clear all
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
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));
h=double(Volume)
if smin==h for yr= linspace(0,1,10);
disp(yr)
end
end
end
i have tried this one but this doesnt make any sense can you help
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
ahh it is wrong.its taking yr=1 for max and min too.can you please check it.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by