How to improve the Slope Field code?

4 次查看(过去 30 天)
I am trying to create my slope fielld manually. Is there any advice how to improve my appearance of the Slope Field? I have read How to Draw a Slope Field in MATLAB but i could not understand how to use Use the slope_field() Function
syms y(x) % Define the symbolic function y(x)
% Define the differential equation
eq = diff(y, x) == x;
% Solve the general solution of the differential equation
gsol = dsolve(eq);
% Define the initial condition and solve the particular solution
cond = y(0) == 3;
psol = dsolve(eq, cond);
% Plot the particular solution
fplot(psol, [-5, 5]);
hold on;
% The slope field for the differential equation
[x, y] = meshgrid(-5:0.5:5, -5:0.5:15);
u = ones(size(x));
v = x; % Because dy/dx = x
quiver(x, y, u, v, 'r');
hold off;

采纳的回答

Athanasios Paraskevopoulos
编辑:Athanasios Paraskevopoulos 2024-3-24
I used the dirfield.m so I had better visualization
f=@(x,y)x
figure;
dirfield(f,-2:0.2:2,-2:0.2:2)
xlabel('$x$','interpreter','latex','fontsize',17);
ylabel('$y$','interpreter','latex','fontsize',17);
title('Slope Field for $\displaystyle\frac{dy}{dx}=x$',...
'interpreter','latex','fontsize',17);
hold on
[x,y] = ode45(f,[-2,2],3);
plot(x,y)
hold off

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by