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 CenterFile Exchange에서 Gamma Functions에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by