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

 采纳的回答

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 个评论

I had found my problem, thanks anyway. btw, your code seem like not able to run.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by