Numerical Differential Equation Matrix Form with Forcing Function

I'm trying to solve a fourth order differential equation with a forcing function t*e^(2t) with ODE45 in matrix form. The method below works fine:
F = @(t,y) [
y(2);
y(3);
y(4);
t*exp(2*t)+4*y(2)-3*y(3)+12*y(1)]
y0 = [0 0 0 -1/4]';
ode45(F, [0 4], y0);
But when I try a matrix form of the system, the forcing function returns an error for an undefined t.
A = [0 1 0 0
0 0 1 0
0 0 0 1
12 4 -3 0]
b = [0 0 0 -t*exp(2*t)]'
y0 = [0 0 0 -1/4]'
F = @(t, Y, A, b) A*Y+b;
ode45(@(t,Y) F, [0,4], y0)
I've used this method for undriven systems of first-order equations. Does anyone know how to modify the code to fix the error?

2 commentaires

It's a bit difficult to see what's going on when your original ode has been reduced to 4 systems of equations as seen in your code, especially in the form as a matrix. Could you post the original equations?
Timothy Sullivan
Timothy Sullivan le 26 Mai 2018
Modifié(e) : Timothy Sullivan le 26 Mai 2018
The original equation is y''''[t]+3*y''[t]-4*y'[t]-12*y[t]=t*exp(2*t) with y=y'=y''=0 at t=0

Connectez-vous pour commenter.

 Réponse acceptée

You need to make ‘b’ a function of ‘t’, and call it appropriately in ‘F’. Then it works:
A = [0 1 0 0
0 0 1 0
0 0 0 1
12 4 -3 0]
b = @(t) [0 0 0 -t*exp(2*t)]'
y0 = [0 0 0 -1/4]'
F = @(t, Y, A, b) A*Y+b(t);
[T,Y] = ode45(@(t,Y) F(t, Y, A, b), [0,4], y0);
figure(1)
plot(T,Y)
grid

2 commentaires

Thanks! I tried b = @(t) etc. but forgot to change
F = @(t, Y, A, b) A*Y+b
to
F = @(t, Y, A, b) A*Y+b(t)
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by