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.

 Risposta accettata

Matt Fig
Matt Fig il 26 Mag 2011
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 Commenti

Matt Fig
Matt Fig il 26 Mag 2011
O.k., but still,... what values of y and z?
William Duhe
William Duhe il 26 Mag 2011
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 il 26 Mag 2011
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!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by