How to improve the Slope Field code?

조회 수: 4 (최근 30일)
Athanasios Paraskevopoulos
Athanasios Paraskevopoulos 2024년 3월 23일
편집: Athanasios Paraskevopoulos 2024년 3월 24일
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일
편집: 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