필터 지우기
필터 지우기

Finding Coefficients for the particular solution

조회 수: 4 (최근 30일)
Tashanda Rayne
Tashanda Rayne 2023년 10월 18일
댓글: Walter Roberson 2023년 10월 22일
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

채택된 답변

David Goodmanson
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
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.
David Goodmanson
David Goodmanson 2023년 10월 18일
Yes it is just the particular solution, as requested by the OP.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
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)
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
Tashanda Rayne
Tashanda Rayne 2023년 10월 22일
The initial conditions:
y(0) = -25
y'(0) = 4
Walter Roberson
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)
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 = 

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by