用matlab求dy/dx=y+x/y-x的通解
Hi your question is quite difficult to solve out.
Since the common method combined with [dsolve()] + [diff] doesn't work at all.
e.g if you type the following command to generate the general solution of this ODE, the IDE should warn you that "Explicit solution could not be found."
syms y(x)
Sol = dsolve( diff(y,x) == y+x/y-x );
Therefore, my current solution is just alternatively get the graphic answer of your equation. But I will dig further in the field and give a better solution if I would find in future.
Generally, I manually set a x domain at [-8 8], and inital y value at 2, and then I use ode45 command to help me generate the equation graph. Hope you could like it.
Anyhow, here is my code.
clc; clear all; clf
% dy x
% ---- == y + --- - x
% dx y
ode1 = @(x,y)(y+x/y-x);
% assume -8 < x < 8 and initial y0 = 2
[x,y] = ode45(ode1, [-8:.01:8], 2.0);
plot(x, y, 'r', 'linewidth', 4)
xlabel('x'), ylabel('y'), grid on
title('solution to ODE dy/dx = y+x/y-x', 'fontsize', 14)
ylim([min(y)-1E7 max(y)+1E7])
line([0 0], ylim, 'color', 'k', 'linewidth', 2);
line(xlim, [0 0], 'color', 'k', 'linewidth', 2);
The graph should look like