Finding Coefficients for the particular solution
3 views (last 30 days)
Show older comments
Tashanda Rayne
on 18 Oct 2023
Commented: Walter Roberson
on 22 Oct 2023
I have this code for the homogenous portion of the equation but I need help trying to find the particular part. I am trying to avoid using any ODE functions
%Equation: y'' +3y'+3.25y = 3cos(x)-1.5sin(x)
format long
Coefa = 1;
Coefb = 3;
Coefc = 3.25;
x0 = 0; x1 = 25; Yin = -25, Yder = 4,
B = [Yin,Yder]; N = 1000;
x = linspace(0,25,N);
y = zeros(1,N);
R = zeros(1,2);
R = SecondOderODE1(Coefa,Coefb, Coefc);
if abs(R(1)-R(2))>=1/10^6
A = [exp(R(1)*x0),exp(R(2)*x0); exp(x0*R(1))*R(1), R(2)*exp(x0*R(2))];;
C = B./A
for i = 1:1:N
y(i) = real(C(1)*x(i)^R(1)+C(2)*x(i)^R(2));
figure(1)
plot (x,y)
xlabel ('x')
ylabel('y')
grid on
end
else
A = [x0^R(1), R(1)*x0^(R(1)-1); x0^R(2), log(x0)*(x0^(R(2)-1))];
C = B./A
for i = 1:1:N
y(i) = real(C(1)*x(i)^R(1)+log(abs(x(i)))*C(2)*x(i)^R(2));
end
end
figure(1)
plot(x,y)
xlabel ('x')
ylabel('y')
grid on
0 Comments
Accepted Answer
David Goodmanson
on 18 Oct 2023
Edited: David Goodmanson
on 18 Oct 2023
Hi Tashanda,
let u and v be 2x1 vectors with the coefficient of cos as first element, coefficient of sine as second element, and M*u = v.
M = -eye(2,2) +3*[0 1;-1 0] + 3.25*eye(2,2) % since c'= -s s'= c
v = [3;-3/2] % right hand side
u = M\v % particular solution
u =
0.8000 % .8 cos(x) + .4 sin(x)
0.4000
2 Comments
Walter Roberson
on 18 Oct 2023
This matches the main part of the symbolic solution, without the constants of integration terms needed to account for any boundary conditions.
More Answers (1)
Walter Roberson
on 18 Oct 2023
% y'' +3y'+3.25y = 3cos(x)-1.5sin(x)
syms y(x)
dy = diff(y);
d2y = diff(dy);
eqn = d2y + 3*dy + 3.25 * y == 3*cos(x) - 1.5*sin(x)
sympref('abbreviateoutput', false);
sol = dsolve(eqn)
simplify(sol, 'steps', 50)
4 Comments
Walter Roberson
on 22 Oct 2023
% y'' +3y'+3.25y = 3cos(x)-1.5sin(x)
syms y(x)
dy = diff(y);
d2y = diff(dy);
eqn = d2y + 3*dy + 3.25 * y == 3*cos(x) - 1.5*sin(x)
sympref('abbreviateoutput', false);
ic = [y(0) == -25, dy(0) == 4]
sol = dsolve(eqn, ic)
sol = simplify(sol, 'steps', 50)
%cross-check
subs(eqn, y, sol)
simplify(ans)
%numeric form
[eqs,vars] = reduceDifferentialOrder(eqn,y(x))
[M,F] = massMatrixForm(eqs,vars)
f = M\F
odefun = odeFunction(f,vars)
initConditions = [-25 4];
ode15s(odefun, [0 10], initConditions)
So the function stored in odefun is what you would need to to process the system numerically
odefun(x, [y(x); dy(x)])
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!