How to evaluate a unknown variable?

1 Ansicht (letzte 30 Tage)
Miroslav Mitev
Miroslav Mitev am 9 Jul. 2019
Kommentiert: Peter Jarosi am 10 Jul. 2019
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 Kommentar
Guillaume
Guillaume am 9 Jul. 2019
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Peter Jarosi
Peter Jarosi am 9 Jul. 2019
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 Kommentare
Miroslav Mitev
Miroslav Mitev am 10 Jul. 2019
That works, thank you :)
Peter Jarosi
Peter Jarosi am 10 Jul. 2019
You're very welcome! :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by