How can I write these functions to the press
1 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/322141/image.png)
回答(1 个)
Ameer Hamza
2020-6-26
You can use ode45() to solve such a system of ODEs.
ic = [2; 4];
xspan = [0 1];
[x, Q] = ode45(@odeFun, xspan, ic);
y_sol = Q(:,1);
z_sol = Q(:,2);
plot(x, Q);
legend({'y', 'z'}, 'FontSize', 16);
function dQdx = odeFun(x, Q)
% Q(1) <=> y, Q(2) <=> z
y = Q(1);
z = Q(2);
dydx = -2*y + 4*exp(-x) + exp(-1000*z^2);
dzdx = -y*z^2/3;
dQdx = [dydx; dzdx];
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/322375/image.png)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Mathematics and Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!