Finding a variable in a equation

Please, I'm new to MATLAB and I want to know how to solve a problem.
I have two variables with 2000 values (I choose 10 to put here):
x = [ 0 0.25 0.5 0.75 1 1.25 1.5 1.75 2 ];
y = [-3.6621 7.32421 -1.831054 -1.831054 -7.32421 3.6621 -1.83105 0.00023 0.00847]
These variables are in the equation: y = K((e^(x/25)) − 1)
I have to use Ordinary least squares (linear regression) or Semilogarithmic plot to find the "K" with the informations above of x and y.
If I choose linear regression I can use these functions: fit, fittype,fitoptions.
Thanks!

回答 (2 件)

Michael Bouser
Michael Bouser 2016 年 3 月 23 日
編集済み: Michael Bouser 2016 年 3 月 23 日

0 投票

First, apply a little algebra. Rewrite your equation in the form "K=". You are going to need to isolate your variable.
Next, because you are using vector inputs, make sure you use ".*" or "./" to force Matlab to do the math "element by element" if you expect an answer in the form of a vector. I think you need to use exp() to do the "e^" part.
It looks like you are doing ok with using parentheses to "maintain order".

1 件のコメント

Befs .07
Befs .07 2016 年 3 月 25 日
編集済み: Befs .07 2016 年 3 月 25 日
Actually, I have 2000 values of x and y (I choose 5 to put there) and I have to use Ordinary least squares Method. I can use these functions: fit, fittype,fitoptions.
Thanks for all!

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

Roger Stafford
Roger Stafford 2016 年 3 月 25 日

0 投票

The following obtains a least squares value for K:
K = y/(exp(x/25)-1);
I am assuming x and y are still row vectors here and of the same length.

2 件のコメント

Star Strider
Star Strider 2016 年 3 月 25 日
‘Befs .07’ is constrained to using fit, fittype, and fitoptions.
Roger Stafford
Roger Stafford 2016 年 3 月 25 日
Well, if ordinary least squares are called for, do this:
t = exp(x/25)-1;
K = sum(y.*t)/sum(t.^2);

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

カテゴリ

ヘルプ センター および File ExchangeLinear and Nonlinear Regression についてさらに検索

タグ

質問済み:

2016 年 3 月 23 日

編集済み:

2016 年 3 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by