Matlab中的斜率场和符号解

时间:2017-01-15 20:17:37

标签: matlab math

我是MATLAB的新手,我不确定我做得对。 我有等式

y' +2y +3x^2 + 4x + 5 = 0

我的任务是在范围slope field中绘制该等式的(0,-1)。然后我必须用y0=0象征性地求解方程。然后绘制等式的图形。

axis([-3 6 -3 6])
hold on;
grid on;

function z=ff(x,y)
z=-2*y+3*x^2-4*x+5;
end

%Slope Field I think its working but in wrong range, not (0, -1)
x=-3:0.5:6;
y=-3:0.5:6;
delta=0.2;
for k = 1:length(x)
 for m = 1:length(y)
    plot(x(k), y(m), 'b.')
    eps = delta/sqrt(1 + ff(x(k), y(m))^2);
    plot([x(k) - eps, x(k) + eps],...
    [y(m) - eps * ff(x(k), y(m)),...
     y(m) + eps * ff(x(k), y(m))],'k')
 end
end

%Symbolic solution of the equation

% y0=0; %this is given 
% p = [3 4 5]; %I'm not sure if x0 is going to be the roots of that polynom
%  x0=roots(p);
% plot(x0,y0,'r*')

y=dsolve('Dy+2*y+3*x^2+4*x+5=0','y(0)=0','x');
x=-10:1/100:10; %
plot(x,eval(y)) %solving the equation for y' and then evaluating it
                %but what should x be?
end

结果是一些奇怪的图形,这就是让我觉得我做错了。有什么帮助吗?

0 个答案:

没有答案