Differential Equation ODE45
1 次查看(过去 30 天)
显示 更早的评论
The equation shown below represents x as a function of t.
Write the Matlab code that uses ode45 to numerically solve for values of x for the range of t=0 to t=4.4 if x=3 at t=0.
The first function in your solution should have this format:
Function name: ode_main
Inputs: none
Outputs:
1. list of t values
2. list of x values
Example call:
[t x]=ode_main()
Hints:
Solve the given equation for dx/dt.
Place that equation in a subfunction or anonymous function.
The time span should be a list of two numbers - the start and end times.
Call ode45 with the appropriate inputs and outputs.
I know this is simple for y'all out there, but I am just starting in MatLab and I'm not sure where I went wrong in my program. Here is my code to the problem given above:
function [tspan, x] = ode_main(time)
% This function has 1 input which is an end time
% It returns 2 outputs: a list of the time values
% : a list of the x values that coorelate to the time
% value.
tspan = [0 time];
% The initial condition was givin in the problem
x0 = 3;
dx = @(t,x)((x-6)./(3*t+1));
[t, x] = ode45(dx,tspan,x0);
return
2 个评论
回答(1 个)
Francisco J. Triveno Vargas
2024-9-17
Hello my friend,
try this,
Regards
Francisco
tspan = [0 5];
% The initial condition was given in the problem
x0 = 3;
dx = @(t,x)((x-6)./(3*t+1));
[t, x] = ode45(dx,tspan,x0);
figure;plot(t,x); grid on
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!