plotting a linear equation
495 次查看(过去 30 天)
显示 更早的评论
How do I plot a linear equation y=mx+b?
So let's say I have this:
b0= 3 where b0 is the y-intercept b1= 4 where b1 is the x coefficient
Then:
Y= b0-b1*X
How do I plot this?
0 个评论
回答(4 个)
per isakson
2012-7-25
Try:
b0 = 3;
b1 = 4;
f = @(x) b0-b1*x;
ezplot( f, 0, 5 )
1 个评论
Sergio E. Obando
2024-11-12,20:32
Just a note that as of R2016a, ezplot is no longer recommended. If anyone is reading this now, the code would still work or you can update to:
b0 = 3;
b1 = 4;
f = @(x) b0-b1*x;
fplot( f,[0,5])
Elizabeth
2012-7-25
编辑:DGM
2024-11-12,20:50
Or:
By all means, the solution method above will work. However, as your function increases in complexity, that command becomes more and more expensive. Try defining your domain x, then, as a vector:
b0=3; b1=4;
x= linspace(xmin,xmax, n); % Adapt n for resolution of graph
y= b0-b1*x;
plot(x,y)
4 个评论
Nicholas Copsey
2020-3-28
xmin, xmax, and n are things you can change in the code for various views of the graph
DGM
2024-11-12,20:54
To clarify:
% curve parameters
b0 = 3; % y-intercept
b1 = 4; % (negative) slope
% define x
xmin = 0; % pick these as needed
xmax = 1;
n = 100; % number of samples
x = linspace(xmin,xmax, n);
% calculate y from x
y = b0 - b1*x;
plot(x,y)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!