Borrar filtros
Borrar filtros

How do I plot blue asterisks on the x and y intercepts of a linear function on a 2D graph?

2 visualizaciones (últimos 30 días)
%cartesian plane
p = [-20,20];
q = p-p;
hold on;
plot(p,q);
plot(q,p);
grid on;
% getting the function from the user.
y = input("Introduce a linear function : ");
Unable to run the 'fevalJSON' function because it calls the 'input' function, which is not supported for this product offering.
ezplot(y);
% now how do i plot blue asterisks on the x and y intercepts of the
% function the user just introduced?

Respuestas (1)

Chunru
Chunru el 1 de Sept. de 2022
% getting the function from the user.
% ystr = input("Introduce a linear function a*x+b: ", "s");
ystr ="3*x -6";
y = str2func("@(x)" + ystr);
xintercept = fsolve(y, 0);
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
yintercept = y(0);
fplot(y)
hold on
xline(0, 'r'); yline(0, 'r');
plot(xintercept, 0, 'b*');
plot(0, yintercept, 'b*');
grid on

Categorías

Más información sobre Line 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