Finding Coefficients for the particular solution

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,
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);
Unrecognized function or variable 'SecondOderODE1'.
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

 Risposta accettata

David Goodmanson
David Goodmanson il 18 Ott 2023
Modificato: David Goodmanson il 18 Ott 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 Commenti

This matches the main part of the symbolic solution, without the constants of integration terms needed to account for any boundary conditions.
Yes it is just the particular solution, as requested by the OP.

Accedi per commentare.

Più risposte (1)

% 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)
eqn(x) = 
sympref('abbreviateoutput', false);
sol = dsolve(eqn)
sol = 
simplify(sol, 'steps', 50)
ans = 
I am not sure if using dsolve counts as an "ode function" or not?

4 Commenti

I cannot use dsolve, is there another way to solve?
I am not able to recognize boundary conditions in what you posted, so as far as I can tell you cannot proceed numerically.
The initial conditions:
y(0) = -25
y'(0) = 4
% 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)
eqn(x) = 
sympref('abbreviateoutput', false);
ic = [y(0) == -25, dy(0) == 4]
ic = 
sol = dsolve(eqn, ic)
sol = 
sol = simplify(sol, 'steps', 50)
sol = 
%cross-check
subs(eqn, y, sol)
ans(x) = 
simplify(ans)
ans(x) = 
symtrue
%numeric form
[eqs,vars] = reduceDifferentialOrder(eqn,y(x))
eqs = 
vars = 
[M,F] = massMatrixForm(eqs,vars)
M = 
F = 
f = M\F
f = 
odefun = odeFunction(f,vars)
odefun = function_handle with value:
@(x,in2)[in2(2,:);in2(2,:).*-3.0-in2(1,:).*(1.3e+1./4.0)+cos(x).*3.0-sin(x).*(3.0./2.0)]
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)])
ans = 

Accedi per commentare.

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by