Numerical solver for system of equations
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I am trying to numerically solve a series of nonlinear equations with an added difficulty. Say we have two functions f and g. Their dependent variables are x and y. We wish to solve the following:
- f(x,y) == 0, -> but I am only allowed to change x
- g(x,y) == 0, -> but I am only allowed to change y
I have been using vpasolve but the problem is that the solver is trying to solve f(x,y) == 0 and g(x,y) == 0 while changing both x and y to meet the conditions.
This problem may seem odd but when solving for parameter estimates using maximum likelihood estimators (MLEs) this is what you have to do.
I figure there is a way to tweak the matlab expression but I do not know how to phrase my question to simply Google it. Hopefully, some of you can assist.
I have also attached the Mathematica output that I am trying to numerically approximate in matlab. There are four equations and four parameters.
0 comentarios
Respuestas (1)
John D'Errico
el 5 de Abr. de 2016
No. There is no such requirement when solving MLE problems. I would suggest that you misunderstand MLE (or basic algebra) if you state that as fact.
If your goal is to solve the problem
f(x,y) == 0
for x, SUBJECT to the constraint that y is fixed, then this is just a call to solve, solving for the variable x. You will then get a relation for x, AS A FUNCTION OF y.
You could then substitute that expression for x into the second equation, then solving for y, and eventually recovering x once y is known. All of this is basic high school algebra, how you might solve the problem using pencil and paper. It is also similar to what you will get when you just call solve on the two equations.
So, lets see what solve does, if you just throw both equations into solve.
syms x y
E1 = x + y == 3;
E2 = x^2 + y^2 == 25;
xy = solve(E1,E2);
xy.x
ans =
41^(1/2)/2 + 3/2
3/2 - 41^(1/2)/2
xy.y
ans =
3/2 - 41^(1/2)/2
41^(1/2)/2 + 3/2
Now, as you MIGHT do it using pencil and paper, solving for x first, then eliminating x from the second equation.
x_y = solve(E1,x)
x_y =
3 - y
subs(E2,x,x_y)
ans =
(y - 3)^2 + y^2 == 25
y_final = solve(subs(E2,x,x_y),y)
y_final =
3/2 - 41^(1/2)/2
41^(1/2)/2 + 3/2
Now recover x.
x_final = subs(x_y,y,y_final)
x_final =
41^(1/2)/2 + 3/2
3/2 - 41^(1/2)/2
Same result.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!