How to evaluate a unknown variable?

조회 수: 3 (최근 30일)
Miroslav Mitev
Miroslav Mitev 2019년 7월 9일
댓글: Peter Jarosi 2019년 7월 10일
I am trying to evaluate a specific variable, i.e., lambda from the following expression:
alpha=0.9;
g=[3, 2, 1];
N=10;
P=5;
sum(( lambda*(2-alpha)-sqrt(lambda*alpha*(lambda*alpha+g.*4*(1-alpha))) ) ./ ( g.*2*lambda*(alpha-1) )) = N*P
Which function shall I use to find the value of lambda that satisfies the equality above, since it is the only unknown variable?
  댓글 수: 1
Guillaume
Guillaume 2019년 7월 9일
You could use fzero if your equation made sense. On the left side of your equation you have a 3 element vector (with 3 different values obviously). On the right hand side you have a scalar.

댓글을 달려면 로그인하십시오.

채택된 답변

Peter Jarosi
Peter Jarosi 2019년 7월 9일
Using fsolve:
alpha=0.9;
g=[3, 2, 1];
N=10;
P=5;
f = @(lambda) sum(( lambda*(2-alpha)-sqrt(lambda*alpha*(lambda*alpha+g.*4*(1-alpha))) ) ...
./ ( g.*2*lambda*(alpha-1) )) - N*P;
lambda0 = 1;
options = optimoptions('fsolve','Display','iter','Algorithm','levenberg-marquardt');
lambda = fsolve(f, lambda0, options);
  댓글 수: 2
Miroslav Mitev
Miroslav Mitev 2019년 7월 10일
That works, thank you :)
Peter Jarosi
Peter Jarosi 2019년 7월 10일
You're very welcome! :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by