Trouble doing loops for specific values
2 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
回答(1 个)
Star Strider
2016-1-30
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 个评论
Star Strider
2016-1-30
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!