I have data point which fits the line y=mx+c ? How can I write code for this?

回答 (2 件)

sixwwwwww
sixwwwwww 2013 年 12 月 7 日
write as follow
x = 0:100;
m = 3;
c = 4;
y = m * x + c;
plot(x, y)

7 件のコメント

RS
RS 2013 年 12 月 7 日
If I dont know value of m and c so how can I fit data point using y=mx+c
sixwwwwww
sixwwwwww 2013 年 12 月 7 日
then use curve fitting tool. see
doc cftool
if you have x and y given then use directly
cftool(x, y)
RS
RS 2013 年 12 月 7 日
ok but I want to plot a line y=x in this and want to find out value of c in my output and angle between two lines y=mx and y=mx+c.
sixwwwwww
sixwwwwww 2013 年 12 月 7 日
if values of x and y are given then you can do as follow. I suppose you x and y vectors then:
m = (y(2) - y(1)) / (x(2) - x(1));
c = x(1) - m * y(1);
RS
RS 2013 年 12 月 7 日
How can I write for any arbitrary data set of x and y, first fit as y=mx+c and from this fit find c and then with the help of other line y=x it will find angle between two lines ?
sixwwwwww
sixwwwwww 2013 年 12 月 7 日
The problem is that in order to plot the equation you need to have 3 known values and one unknown value because there 4 values in equation x, y, m and c. So you should atleast have three values or if you just plot some random values of x and y and then want to find m and c then using cftool is the best option
sixwwwwww
sixwwwwww 2013 年 12 月 8 日
編集済み: sixwwwwww 2013 年 12 月 8 日
If you are given values of x and y then you can compute m and c as follow:
fitvars = polyfit(x, y, 1);
m = fitvars(1);
c = fitvars(2);

サインインしてコメントする。

chitresh
chitresh 2013 年 12 月 7 日

1 投票

>>syms x y m c
>> solve(' y = m * x + c')
i think this gone solve your question, if it is solved accept the answer

4 件のコメント

RS
RS 2013 年 12 月 8 日
I am getting value of x here after giving value of m, y and c but in problem I don't know value of m and c only x and y is known to me.
How can I write for line passes through if x and y are given and find slope and c?
chitresh
chitresh 2013 年 12 月 13 日
dear here m and c where constant, by substituting the value of x and y you get your answer and you can plot your lines too for this plz go through linear programming mathematics here is a link for this
chitresh
chitresh 2013 年 12 月 15 日
if you done with your question, mark the answer accepted
Image Analyst
Image Analyst 2013 年 12 月 15 日
And officially Accept answers in more than 30 other questions that you've asked.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

タグ

質問済み:

RS
2013 年 12 月 7 日

コメント済み:

2013 年 12 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by