Find Coefficients of a 5th order ODE without ode45
1 view (last 30 days)
Show older comments
The code below I came up with, I am getting the correct roots but the constants are wrong and the graph is not correct either. Can you please help me figure out why it's coming out incorrect.
%Eqn: y'''''-5y'''+4y' = 0
format long
Coefa = 1;
Coefb = 0;
Coefc = -5;
Coefd = 0;
Coefe = 4;
Coeff = 0;
x0 = 0; Yin = 3, Yder1 = -5, Yder2 = 11 , Yder3 = -23, Yder4 = 47,
B = [Yin Yder1 Yder2 , Yder3 Yder4]; N = 1000;
x = linspace(0,25,N);
y = zeros(1,N);
R = zeros(1,4);
R = SecondOderODE1(Coefa,Coefb, Coefc,Coefd, Coefe,Coeff);
if abs(R(1)-R(4))>=1/10^6
A = [exp(R(1).*x0), exp(R(2).*x0), exp(R(3).*x0), exp(R(4).*x0), exp(R(5).*x0); exp(x0.*R(1)).*R(1), R(2).*exp(x0.*R(2)), exp(x0.*R(3)).*R(3), exp(x0.*R(4)).*R(4), exp(x0.*R(5)).*R(5)];
C = B./A
for i = 1:1:N
y(i) = real(C(1)*exp(R(1)*x(i)) + C(2)*exp(R(2)*x(i)))+ C(3)*exp(R(3)*x(i))+ C(4)*exp(R(4)*x(i))+ C(5)*exp(R(5)*x(i));
figure(1)
plot (x,y)
xlabel ('x')
ylabel('y')
grid on
end
end
figure(1)
plot(x,y)
xlabel ('x')
ylabel('y')
grid on
0 Comments
Accepted Answer
Torsten
on 22 Oct 2023
syms t x(t)
Dx = diff(x,t);
D2x = diff(x,t,2);
D3x = diff(x,t,3);
D4x = diff(x,t,4);
D5x = diff(x,t,5);
eqn = D5x-5*D3x+4*Dx == 0;
conds = [x(0) == 3,Dx(0) == -5,D2x(0) ==11, D3x(0) == -23, D4x(0)==47];
sol = dsolve(eqn,conds)
fplot(sol,[0 1])
4 Comments
Torsten
on 22 Oct 2023
Edited: Torsten
on 22 Oct 2023
The roots could be complex-valued or a root could be of higher order than 1. How do you handle this with your code ?
In short: a solution without dsolve or ODE45 will get much more complex than the code you posted.
For the equation posted, a paper-and-pencil solution will be easiest - and it doesn't use ODE45 or dsolve :-)
More Answers (0)
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!