Writing a long equation in MATLAB

9 ビュー (過去 30 日間)
Selim Elbadri
Selim Elbadri 2022 年 8 月 25 日
コメント済み: Voss 2022 年 8 月 28 日
Hi,
I need help writing this equation in MATLAB:
where:
My proposed code is:
d = ((1/(gamma*(abar(t-1,1) - a(t-1,1))))*(1+(a(t-1,1)/(gamma*(abar(t-1,1) - a(t-1,1))))));
GAMMA = gamma*(abar(t-1,1) - a(t-1,1);
exp(-rho*t)*gamma*(abar(t-1,1) - a(t-1,1))*((exp(-(rho+d)*t)/c0)-(exp(-rho*t)/(GAMMA*d))))^(-1);
The code doesn't generate the right numbers though. Is it written correctly?
Thanks!
  1 件のコメント
David Hill
David Hill 2022 年 8 月 25 日
Show us your code and ask a specific question. You should also describe or attach your variables and constants.

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

採用された回答

Voss
Voss 2022 年 8 月 26 日
There are a couple of errors with the parentheses:
d = ((1/(gamma*(abar(t-1,1) - a(t-1,1))))*(1+(a(t-1,1)/(gamma*(abar(t-1,1) - a(t-1,1))))));
GAMMA = gamma*(abar(t-1,1) - a(t-1,1));
% ^ you were missing this parenthesis
c = exp(-rho*t)*gamma*(abar(t-1,1) - a(t-1,1))*((exp(-(rho+d)*t)/c0)-(exp(-rho*t)/(GAMMA*d)))^(-1);
% ^ and you had an extra parenthesis in here
In addition to that, there are some extraneous parentheses that won't affect the result. Removing those, the code looks like this:
d = 1/(gamma*(abar(t-1,1) - a(t-1,1)))*(1+(a(t-1,1)/(gamma*(abar(t-1,1) - a(t-1,1)))));
GAMMA = gamma*(abar(t-1,1) - a(t-1,1));
c = exp(-rho*t)*gamma*(abar(t-1,1) - a(t-1,1))*((exp(-(rho+d)*t)/c0)-exp(-rho*t)/(GAMMA*d))^-1;
In addition to that, you can calculate GAMMA first and use it in the other expressions to shorten them a bit:
GAMMA = gamma*(abar(t-1,1) - a(t-1,1));
d = 1/GAMMA*(1+a(t-1,1)/GAMMA);
c = exp(-rho*t)*GAMMA*((exp(-(rho+d)*t)/c0)-exp(-rho*t)/(GAMMA*d))^-1;
Throughout, I've assigned your last expression to the variable c.
  3 件のコメント
Selim Elbadri
Selim Elbadri 2022 年 8 月 27 日
Thanks a lot!
Voss
Voss 2022 年 8 月 28 日
You're welcome!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGamma Functions についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by