Differential Equation ODE45

1 回表示 (過去 30 日間)
Stephanie
Stephanie 2011 年 11 月 22 日
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 件のコメント
Walter Roberson
Walter Roberson 2011 年 11 月 22 日
I do not see an "equation shown below" ?
Jan
Jan 2011 年 11 月 22 日
@Stephanie: You forgot to explain, why you think, that something went wrong.

サインインしてコメントする。

回答 (1 件)

Francisco J. Triveno Vargas
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

この質問は閉じられています。

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by