plotting a linear equation

625 次查看(过去 30 天)
Andy
Andy 2012-7-25
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?

回答(4 个)

per isakson
per isakson 2012-7-25
Try:
b0 = 3;
b1 = 4;
f = @(x) b0-b1*x;
ezplot( f, 0, 5 )

Elizabeth
Elizabeth 2012-7-25
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:
MATLAB code
b0=3; b1=4;
x= linspace(xmin,xmax, n); % Adapt n for resolution of graph
y= b0-b1*x;
plot(x,y)
  3 个评论
Naga Sai
Naga Sai 2017-5-22
编辑:Naga Sai 2017-5-22
xmin,xmax,n undefined variables
Nicholas Copsey
Nicholas Copsey 2020-3-28
xmin, xmax, and n are things you can change in the code for various views of the graph

请先登录,再进行评论。


Ben Le
Ben Le 2015-12-9
bo = 3;
b1 = 4;
% You can choose any range of x. In this case I chose x is from -50 to +50
x = -50:50;
plot(x,y)

Andy
Andy 2012-7-25
How do I get that into the same graphs? I have points for my data and the equation above is the linear regression. Ezplot gave me two graphs. :(. I want both the points and the linear equation graphed in one figure.

类别

Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by