How to write a basic loop

[EDIT: Thu May 26 02:39:10 UTC 2011 - Reformat - MKF]
z = 0.05;
y = 1/20;
f = @(x) (10.^(-15).*x.^(3).*exp((x.^2).^(-1)/4).*y.^(-1)).^(1/5)-z;
fzero(f,1);
This is my given command line and I need to write a loop in order to solve for a range of z and y values? How would I go about this? I have tried just giving a y value such as:
for z = 0.05:.06,
f = @(x) (10.^(-15).*x.^(3).*exp((x.^2).^(-1)/4).*.05.^(-1)).^(1/5)-z;
fzero(f,1)
and letting it try and run a simple loop for z but it doesn't seem to work. It seems easy but its giving me a lot of trouble. Thanks ahead of time for any help.

 채택된 답변

Matt Fig
Matt Fig 2011년 5월 26일

2 개 추천

Your question is confusing because you say you want to solve for a range of x and y values but you are looping over z values. Could you show the values you actually want to use?
%
%
%
EDIT After some clarifying comments.
Here is an example with some range for y and z that I made up.
opts.Display = 'off';
y = 0:.01:1; % Some y values.
z = 0:.01:.14; % Some z values.
H = nan(length(y),length(z));
for ii = 1:length(y)
for jj = 1:length(z)
f = @(x) (10.^(-15).*x.^(3).*...
exp((x.^2).^(-1)/4).*y(ii).^(-1)).^(1/5)-z(jj);
try
H(ii,jj) = fzero(f,1,opts);
catch
end
end
end
H % Display the results. Row is y, column is z

댓글 수: 3

Matt Fig
Matt Fig 2011년 5월 26일
O.k., but still,... what values of y and z?
William Duhe
William Duhe 2011년 5월 26일
O.k I was a little jumbled up in my initial writing.... I need to solve for x, with varying z and y values. Such as the original equation I posted:
z = 0.05;
y = 1/20;
f = @(x) (10.^(-15).*x.^(3).*exp((x.^2).^(-1)/4).*y.^(-1)).^(1/5)-z;
fzero(f,1);
I want to run a loop for that with different values of z and/or y. I hope this makes sense, I'm still kind of a rookie to Matlab and its rough for me =)
William Duhe
William Duhe 2011년 5월 26일
This is awesome, I have a meeting tomorrow to figure out a little bit more about what range of values I'm going to be running, I'll let ya know if I have any other questions thanks!

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

추가 답변 (0개)

카테고리

도움말 센터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