How to solve one parameter in a multiple variable equation

Hi :-)
I have an equation with one unknown variable (x) that I need to solve:
F = x*((1-2*p*(((1-(x/f))/(2*(x/f)))))/(1-(p*((1-(x/f))/(2*(x/f))))))-e;
p,f and e are defined. How can I solve x?
Thanks

 採用された回答

Star Strider
Star Strider 2015 年 6 月 24 日

0 投票

It depends on what you mean by ‘solve’.
If you want to find the values where it equals zero, use fzero:
F = @(x) x.*((1-2.*p.*(((1-(x./f))./(2*(x./f)))))./(1-(p.*((1-(x./f))./(2*(x./f))))))-e;
X = fzero(f, 1);
for example.
Using the Symbolic Math Toolbox, it simplifies to:
F = ((- 2*p - 2)*x^2 + (2*e + e*p + 2*f*p)*x - e*f*p)/((- p - 2)*x + f*p);
so you might want to use that instead.

2 件のコメント

Katharina Albert
Katharina Albert 2015 年 6 月 24 日
Thank you, it works. So now I have a row of data and need this equation to solve for each row. How can I get that?
thank you :-)
for p=[p1 p2 p2 .. px] and e=[e1 e2 e3 .. ex] but only one f - value how can i calculate x1 as function of p1, e2 and f?
Star Strider
Star Strider 2015 年 6 月 24 日
This is likely the easiest way:
F = @(x,e,p,f) ((- 2.*p - 2).*x.^2 + (2*e + e.*p + 2*f.*p).*x - e.*f.*p)./((- p - 2).*x + f.*p);
f = 10; % Create Data
p = randi(9, 5, 1);
e = randi(9, 5, 1);
for k1 = 1:length(p)
for k2 = 1:length(e)
x(k1,k2) = fzero(@(x) F(x,e(k2),p(k1),f), 1);
end
end
Here, ‘e’ and ‘p’ are the respective vectors for those variables, and ‘x’ is a matrix of solutions for the respective variables, so that ‘x(2,3)’ is the solution for ‘p(2),e(3)’.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCondensed Matter & Materials Physics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by