Differential Equation ODE45
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Stephanie
el 22 de Nov. de 2011
Respondida: Francisco J. Triveno Vargas
el 17 de Sept. de 2024
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 comentarios
Jan
el 22 de Nov. de 2011
@Stephanie: You forgot to explain, why you think, that something went wrong.
Respuestas (1)
Francisco J. Triveno Vargas
el 17 de Sept. de 2024
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 comentarios
La pregunta está cerrada.
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!