Help please solve 3nd Order Differential Equation using ODE45

Help please solve 3nd Order Differential Equation using ODE45.
y′′′ − 3 y′′ + 3 y′ − y = 2e^x ;
x[3,3 ] ;
y(3) = 0 ;
y(3) = 1 ;
y′′(3) = 1;
its my first experience in matlab. so please with details:)

 Risposta accettata

Follow the 2nd Order example given in the doc (the one under "van der Pol equation"):
Simply code up what they have in this example, but your y variable is going to be 3 elements instead of 2 elements. Also, your "x" is going to be the same as the example "t". So you will have a 3-element initial condition vector, and your integration range will be different per above. You will need to replace the example dydt line with your equivalent dydt line.
E.g., this
y′′′ − 3 y′′ + 3 y′ − y = 2e^x
would make your dydt this:
dydt = [y(2); y(3); 3*y(3) - 3*y(2) + y(1) + 2*exp(t)];

4 Commenti

can you explain
dydt = [ y(2); y(3); 3*y(3) - 3*y(2) + y(1) + 2*exp(t)];
y(2) and y(3);
why 3*y(3);
why plus 2*exp(t)
don't understand
You are simply solving this equation for y'''
y′′′ − 3 y′′ + 3 y′ − y = 2e^x
which becomes
y′′′ = 3 y′′ − 3 y′ + y + 2e^x
Stuff that was on the lhs (− 3 y′′ + 3 y′ − y) and moved to the rhs switches signs. Stuff that was already on the rhs (2e^x) keeps the sign it already had.
First start with this definition for getting the "scalar" y and its derivatives into a 3-element vector:
y(1) = y
y(2) = y'
y(3) = y''
Then this relationship
d(y)/dx = y'
results in the dydt(1) = y(2) part
And this relationship
d(y')/dx = y''
results in the dydt(2) = y(3) part
And the dydt(3) part is as explained above, by simply rearranging your DE with y''' on the lhs and everything else on the rhs.
great!!! I understand now.
dydt = [ y(2); y(3); 3*y(3) - 3*y(2) + y(1) + 2*exp(t)];
why we write it "y(2); y(3);" in equation? i mean i dont understand syntax yet. last question: how i can define
y(3) = 0 ;
y(3) = 1 ;
y′′(3) = 1;
about zero i read some information, but about non zero i cannot find information
This syntax creates a 3-element column vector directly (when you use the semi-colon as a separator inside the square brackets [ ] the elements are created in a column):
dydt = [ y(2); y(3); 3*y(3) - 3*y(2) + y(1) + 2*exp(t)];
does the same thing as if you had written each derivative equation out individually as follows:
dydt = zeros(3,1); % Create the 3-element column vector for result
dydt(1) = y(2); % The y' part
dydt(2) = y(3); % The y'' part
dydt(3) = 3*y(3) - 3*y(2) + y(1) + 2*exp(t); % The y''' part
For the initial conditions you can just use the syntax that is in the link example and supply a literal starting condition 3-element vector. For the range you can also supply a literal 2-element vector per the example. E.g., if your derivative function is coded up in a file called my_dydt.m, then the ode45 call could look like this:
[t,y] = ode45(@my_dydt,[-3 3],[0;-1;1]);
For plotting the results, keep in mind that that the example only had two columns to plot, y(:,1) and y(:,2), but you might want to plot all three columns of your result, y(:,1) and y(:,2) and y(:,3).

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by