Finding Coefficients for the particular solution
조회 수: 5 (최근 30일)
이전 댓글 표시
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
채택된 답변
David Goodmanson
2023년 10월 18일
편집: David Goodmanson
2023년 10월 18일
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
Walter Roberson
2023년 10월 18일
This matches the main part of the symbolic solution, without the constants of integration terms needed to account for any boundary conditions.
추가 답변 (1개)
Walter Roberson
2023년 10월 18일
% 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
Walter Roberson
2023년 10월 22일
% 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)])
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!