方法一:使用符号计算工具箱
syms x y(x)
eqn = diff(y, x, 2) + 2 * diff(y, x) + exp(x) == 0;
sol = dsolve(eqn);
sol = simplify(sol);
方法二:转化为一阶方程组进行数值求解
syms x y1(x) y2(x)
eqns = [diff(y1, x) == y2, diff(y2, x) == -2*y2 - exp(x)];
init = [初始值1; 初始值2];
[X, Y] = ode45(@(x,y) [y(2); -2*y(2) - exp(x)], [起始点, 结束点], init);
注意:在数值求解中,需要给定初始条件和求解区间。
--- 光学专家Gpt |