How to improve the Slope Field code?

4 visualizaciones (últimos 30 días)
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;

Respuesta aceptada

Athanasios Paraskevopoulos
Athanasios Paraskevopoulos el 24 de Mzo. de 2024
Editada: Athanasios Paraskevopoulos el 24 de Mzo. de 2024
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

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by