Trouble doing loops for specific values
Afficher commentaires plus anciens
Hi. I have problem with loops.
I want to calculate for specific values of P which is 0.5, 0.64, 0.7, 1.0, 6.7. How do I do that?
As from below, this code will let P be 0.5, 0.6, 0.7, 0.8, 0.9. But I dont want it to be like that. I want it as specific values like I mentioned just now.
P=0.5;
for i=2:5
P = Pr+0.1;
sol = bvp4c(@(x,y)VK(x,y,n),@VKbc,sol);
fprintf('\n');
fprintf('n \t-Winfinity \n');
plot(sol.x,-sol.y(3,:),lines{i});
end
Thank you in advance!
Réponses (1)
Star Strider
le 30 Jan 2016
Apparently, this is part of a larger script.
I would define ‘P’ in your loop by assigning it as a vector and then referring to individual elements of the vector:
Pv = [0.5, 0.64, 0.7, 1.0, 6.7];
for i=1:length(Pv)
P = Pv(i);
sol = bvp4c(@(x,y)VK(x,y,n),@VKbc,sol);
fprintf('\n');
fprintf('n \t-Winfinity \n');
plot(sol.x,-sol.y(3,:),lines{i});
end
I can’t run this so I can’t check it. Make appropriate changes so that it works in your code.
2 commentaires
Star Strider
le 30 Jan 2016
I don’t understand what you’re doing.
My idea was to replace this line:
Pr = [0.5, 0.64, 0.7, 1.0, 6.7];
with:
Pv = [0.5, 0.64, 0.7, 1.0, 6.7];
Your loop then does what I intend for it to do.
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!