Borrar filtros
Borrar filtros

How to do loops and execute values from graphs of bvp4c

1 visualización (últimos 30 días)
Day Rosli
Day Rosli el 27 de En. de 2016
Hi all. I have wrote a code, in which I want MATLAB to plot graphs of -W(eta) versus eta, for n=1 and n=1.1.
This is the code:
function Script4
n=1.0;
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 -W versus eta')
lines = {'b-','c-'};
ylabel('-W(eta)')
xlabel('eta')
drawnow
hold on
for i=1:2
n = n+0.1;
sol = bvp4c(@(x,y)VK(x,y,n),@VKbc,sol);
fprintf('\n');
fprintf('n \t-W \n');
plot(sol.x,-sol.y(3,:),lines{i});
for k = 1:length(x)
fprintf('%3.2f %8.4f\n', x(k),-y(3,k));
drawnow
end
end
legend('n = 1.0','n=1.1',1);
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
The problem is now,
1) Is this the right way to make loop for increasing the value of n? I want it start from n=1.0 increase by 0.1 up to 1.1.
for i=1:2
n = n+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
2) Also, I want MATLAB to execute or give me values of -W(eta) from eta=0 to eta=20, for each n. Is that the right way to call it? I mean, look at the percent and number I placed. I look at somewhere, I just paste the way they write it on my problem without knowing what the meaning of %3.2 and %8.4. I dont think it is correct but I dont know how to call it.
for k = 1:length(x)
fprintf('%3.2f %8.4f\n', x(k),-y(3,k)));
drawnow
end
Thank you in advance.

Respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by