How to find the value of a variable in MATLAB that exists on both sides of th eequal sign?
25 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kourosh
el 16 de Mayo de 2014
Editada: Randy Souza
el 19 de Mayo de 2014
Does anybody know how we can find the value of a variable in MATLAB that exists on both sides of equal sign, e.g. n in 2n+q=n+r (n is the only variable)?
In this case it is so simple; n=r-q. But what if the equation is very complex and we are not able to transfer the variable to one side?
0 comentarios
Respuesta aceptada
Star Strider
el 16 de Mayo de 2014
If you have the Symbolic Math Toolbox:
syms n q r
Eq = 2*n+q == n+r
n = solve(Eq, n)
produces:
n =
r - q
To solve them numerically for n, make the entire equation equal to zero and use the fzero function:
r = 3;
q = 5;
f = @(n) [2*n+q - (n+r)];
n = fzero(f, 1)
produces:
n =
-2
4 comentarios
Star Strider
el 19 de Mayo de 2014
I don’t know what the equation is, but plotting it:
Nn = linspace(-10,10);
figure(1)
plot(Nn, real(f(Nn)))
grid
shows that the real part doesn’t have a zero crossing anywhere in the region. (It has a small region in the Nn domain where it generates complex values.)
Más respuestas (1)
Brian B
el 16 de Mayo de 2014
If you have the Symbolic Toolbox, you can use:
>> syms n q r
>> solve('2*n+q=n+r','n')
ans =
r - q
Ver también
Categorías
Más información sobre Calculus en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!