I am facing error while solving two 2nd order differential equation in which boundary condition are dependent to each other. Any idea where I am doing wrong??
1 次查看(过去 30 天)
显示 更早的评论
clc
clear all;
close all;
syms psi_1(z)
syms psi_2(z)
K1=1
K2=1
K3=1
Dpsi_1 = diff(psi_1);
Dpsi_2 = diff(psi_2);
%%%%%%%%%% Differential equations %%%%%%%%%%%%%
ode1=diff(psi_1,z,2)-psi_1/K1==K2
ode2 = diff(psi_2,z,2)==K3
%%%%%%%%%% initial conditions %%%%%%%%
cond1 = psi_1(0) == 0;
cond2=psi_1(1)==psi_2(1)
cond3 = Dpsi_1(1) == Dpsi_2(1);
cond4=psi_2(2) == 0.5;
conds_1 = [cond1 cond2];
conds_2 = [cond3 cond4];
psi_1Sol(z) = dsolve(ode1,conds_1)
psi_2Sol(z) = dsolve(ode2,conds_2)
0 个评论
采纳的回答
Oguz Kaan Hancioglu
2023-2-17
Since boundary conditions are related to each variable, solving all odes in one dsolve command may solve your problem.
[psi_1Sol(z), psi_2Sol(z)] = dsolve(ode1,ode2,conds_1,conds_2)
更多回答(1 个)
Torsten
2023-2-17
编辑:Torsten
2023-2-17
syms y1(z) y2(z) z C11 C12 C21 C22
K1 = 1;
K2 = 1;
K3 = 1;
eqn1 = diff(y1,z,2) - y1/K1 == K2;
eqn2 = diff(y2,z,2) == K3;
sol1 = dsolve(eqn1);
var1 = symvar(sol1);
sol1 = subs(sol1,[var1(1),var1(2)],[C11 C12]);
sol2 = dsolve(eqn2);
var2 = symvar(sol2);
sol2 = subs(sol2,[var2(1) var2(2)],[C21 C22]);
eqn1_alg = subs(sol1,z,0)==0;
eqn2_alg = subs(diff(sol1,z),z,1)==subs(diff(sol2,z),z,1);
eqn3_alg = subs(sol1,z,1)==subs(sol2,z,1);
eqn4_alg = subs(sol2,z,2)==0.5;
sol_alg = solve([eqn1_alg,eqn2_alg,eqn3_alg,eqn4_alg],[C11 C12 C21 C22]);
sol1 = subs(sol1,[C11 C12],[sol_alg.C11 sol_alg.C12]);
sol2 = subs(sol2,[C21 C22],[sol_alg.C21 sol_alg.C22]);
figure(1)
hold on
fplot(sol1,[0 1])
fplot(sol2,[1 2])
hold off
grid on
@Oguz Kaan Hancioglu suggestion works, too:
syms psi_1(z)
syms psi_2(z)
K1=1;
K2=1;
K3=1;
Dpsi_1 = diff(psi_1);
Dpsi_2 = diff(psi_2);
%%%%%%%%%% Differential equations %%%%%%%%%%%%%
ode1=diff(psi_1,z,2)-psi_1/K1==K2;
ode2 = diff(psi_2,z,2)==K3;
%%%%%%%%%% initial conditions %%%%%%%%
cond1 = psi_1(0) == 0;
cond2=psi_1(1)==psi_2(1);
cond3 = Dpsi_1(1) == Dpsi_2(1);
cond4=psi_2(2) == 0.5;
conds_1 = [cond1 cond2];
conds_2 = [cond3 cond4];
[psi_1Sol(z), psi_2Sol(z)] = dsolve(ode1,ode2,conds_1,conds_2);
figure(2)
hold on
fplot(psi_1Sol,[0 1])
fplot(psi_2Sol,[1 2])
hold off
grid on
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!