Finding Coefficients for the particular solution
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (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)
sympref('abbreviateoutput', false);
sol = dsolve(eqn)
simplify(sol, 'steps', 50)
4 commentaires
Tashanda Rayne
le 18 Oct 2023
Walter Roberson
le 22 Oct 2023
I am not able to recognize boundary conditions in what you posted, so as far as I can tell you cannot proceed numerically.
Tashanda Rayne
le 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)])
Catégories
En savoir plus sur Symbolic Math Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







