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일
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

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

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Condensed Matter & Materials Physics에 대해 자세히 알아보기

질문:

2015년 6월 24일

댓글:

2015년 6월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by