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

 Akzeptierte Antwort

Star Strider
Star Strider am 24 Jun. 2015
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 Kommentare

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?
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)’.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Condensed Matter & Materials Physics finden Sie in Hilfe-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