フィルターのクリア

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

2 ビュー (過去 30 日間)
mauricio
mauricio 2022 年 8 月 31 日
回答済み: Chunru 2022 年 9 月 1 日
%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?

回答 (1 件)

Chunru
Chunru 2022 年 9 月 1 日
% 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

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by