Clear Filters
Clear Filters

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

2 views (last 30 days)
%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?

Answers (1)

Chunru
Chunru on 1 Sep 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

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!