Need help on loop for an ODE function

This code for an ODE function with boundary condition, and it can only given an answer at selected time,in this coding is at t=1 t. I need to add in a loop with a small time increment, from t=0 to t=20 at increment of t=0.01. Can anyone please help me ? I need to solve this problem.
solinit = bvpinit(linspace(0,1,10),[0,0,]);
sol = bvp4c(@ex1ode,@ex1bc,solinit);
y = linspace(0,1);
u = deval(sol, y);
plot(u(1,:),y)
title ('beta = 1');
xlabel ('u*');
ylabel ('y*');
legend ('t=1');
function dudy = ex1ode(y,u)
t=1;n=1;U = 1; pho = 1; eta = 1;
uini = 0;
dudy = [ u(2)^(1/n)
(pho/eta) *((u(1)-0)/ t)];
end
function res = ex1bc (ua,ub)
t=1;U=1; omega = 1;
res=[ua(1)- U*sin(omega*t)
ub(1)];
end

 Respuesta aceptada

Torsten
Torsten el 16 de Mayo de 2018
t=0.01:0.01:20;
for i=1:numel(t)
solinit = bvpinit(linspace(0,1,10),[0,0]);
sol{i} = bvp4c(@(y,u)ex1ode(y,u,t(i)),@(ua,ub)ex1bc(ua,ub,t(i)),solinit);
end
function dudy = ex1ode(y,u,t)
n=1;U = 1; pho = 1; eta = 1;
uini = 0;
dudy = [ u(2)^(1/n)
(pho/eta) *((u(1)-0)/ t)];
end
function res = ex1bc (ua,ub,t)
U=1; omega = 1;
res=[ua(1)- U*sin(omega*t)
ub(1)];
end
Best wishes
Torsten.

1 comentario

Chee Hao Hor
Chee Hao Hor el 16 de Mayo de 2018
I had found my problem, thanks anyway. btw, your code seem like not able to run.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Preguntada:

el 16 de Mayo de 2018

Comentada:

el 16 de Mayo de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by