フィルターのクリア

Plotting graphs from equation of bvp

2 ビュー (過去 30 日間)
Day Rosli
Day Rosli 2016 年 1 月 23 日
コメント済み: Star Strider 2016 年 1 月 24 日
Hi, I have some problems regarding bvp. It's all about plotting graphs.
This is my code:
function Script
n=0.6;
infinity=20;
solinit = bvpinit(linspace(0,infinity,30),[0 0 0 0 -1]);
sol = bvp4c(@(x,y)VK(x,y,n),@VKbc,solinit);
x = [0:2:20];
y = deval(sol,x);
figure
title('Plots of U versus x')
ylabel('U(x)')
xlabel('x')
drawnow
hold on
for i=1:9
n = n+0.1;
sol = bvp4c(@(x,y)VK(x,y,n),@VKbc,sol);
plot(sol.x,sol.y(1,:));
end
hold off
function yprime = VK(x,y,n)
a = ((1-n)/(n+1))*x;
c = (y(4)^2+y(5)^2)^((1-n)/(n+1));
yprime = [ c*y(4)
c*y(5)
-2*y(1) - a*c*y(4)
y(1)^2 - (y(2)+1)^2 + (y(3)+a*y(1))*c*y(4)
2*y(1)*(y(2)+1) + (y(3)+a*y(1))*c*y(5)];
end
function res = VKbc(ya,yb)
res = [ya(1);ya(2);ya(3);yb(1);yb(2)+1];
end
end
My problem is:
1) I have to plot c aginst x.
Where:
c = (y(4)^2+y(5)^2)^((1-n)/(n+1))
How should I write the code? 2) I also have to plot U', V' and W', all aginst x. Where, (as from the code)
y(1)'= U'=c*y(4),
y(2)' = V'=c*y(5),
y(3)' = W'=-2*y(1) - a*c*y(4).
I hope someone can help me regarding this. Thank you in advance.

採用された回答

Star Strider
Star Strider 2016 年 1 月 23 日
This works:
function Script
n=0.6;
infinity=20;
solinit = bvpinit(linspace(0,infinity,30),[0 0 0 0 -1]);
sol = bvp4c(@(x,y)VK(x,y,n),@VKbc,solinit);
x = [0:2:20];
y = deval(sol,x);
for i=1:9
n = n+0.1;
sol = bvp4c(@(x,y)VK(x,y,n),@VKbc,sol);
xc{i} = sol.x;
yc{i} = sol.y;
cv{i} = (sol.y(4,:).^2+sol.y(5,:).^2).^((1-n)./(n+1)); % Calculate ‘c’
figure(i)
plot(xc{i},yc{i}, xc{i},cv{i});
title('Plots of U versus x')
ylabel('U(x)')
xlabel('x')
legend('y_1(x)', 'y_2(x)', 'y_3(x)', 'y_4(x)', 'y_5(x)', 'c(x)', 'Location','NE')
end
function yprime = VK(x,y,n)
a = ((1-n)/(n+1))*x;
c = (y(4)^2+y(5)^2)^((1-n)/(n+1));
yprime = [ c*y(4)
c*y(5)
-2*y(1) - a*c*y(4)
y(1)^2 - (y(2)+1)^2 + (y(3)+a*y(1))*c*y(4)
2*y(1)*(y(2)+1) + (y(3)+a*y(1))*c*y(5)];
end
function res = VKbc(ya,yb)
res = [ya(1);ya(2);ya(3);yb(1);yb(2)+1];
end
end
I calculated ‘c’, and created cell arrays to save the solutions at each value of ‘i’. You can use ‘xc’, ‘yc’, and ‘cv’ in other parts of your code. See the documentation on cell arrays for details on how to work with them. (In this instance, they should be relatively easy to work with. The plot call in the loop is an example of how to address them.)
I don’t know how you want your solutions to be plotted. Here, I plotted 9 separate figures, since it would be extremely difficult for you to see the individual plots if you plotted them all in one figure. I also added a legend call to each figure so you could see what the lines are.
  8 件のコメント
Day Rosli
Day Rosli 2016 年 1 月 24 日
Thank you so much again, Star Strider. I believe, you have share alot of your knowledge to others. And Im one of them and Im so glad. Wish you the best in your life and career!
:)
Star Strider
Star Strider 2016 年 1 月 24 日
As always, my pleasure!
Thank you! I wish you the same!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by