how to solve ode if value of constant is vector
2 次查看(过去 30 天)
显示 更早的评论
function [dydt] = diffvar(t,y)
dydt=-k*y+a;
end
end
in this if a is vector how to solve
0 个评论
回答(1 个)
Ameer Hamza
2020-10-21
编辑:Ameer Hamza
2020-10-21
If k and a are constant vectors of equal length the following will work
k = rand(10, 1);
a = rand(10, 1);
IC = zeros(10, 1);
tspan = [0 10];
[t, y] = ode45(@(t,y) diffvar(t,y,k,a), tspan, IC)
plot(t, y)
function [dydt] = diffvar(t,y,k,a)
dydt=-k.*y+a;
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!