Originally Posted by: pTM Muchas gracias Razonar. Pero no entiendo come funciona. Puedes explicarme el methodo con un ejemplo mas sencillo ? O por favor enviame a una pagina con una explicacion.
Parece que "target" estructura el asunto y "Jx","J(x)" definen el metodo de resolucion. Pero cual es ? Y por fin "f" es el algoritmo que resolve la ecuacion.
Gracias,
Pedro
Hola Pedro. Sí, hay varios detalles "técnicos", por decirles de alguna forma.
A ver si estos comentarios explican un poco la solución.
La llamé "target" porque es el nombre que suele darse a la función que se quiere optimizar. Si te fijas en la forma en que está resuelto en Mathcad, el bloque given / find resulta en una función, no en los valores de las raíces. Esto porque tienes un sistema con 3 incógnitas y 2 ecuaciones: f ( PzSb ) = Find( Pas, Psb ). La función target no sería esa "f", aún.
Por otro lado, la función al_nlesolve se vuelve muy lenta si no se le da el Jacobiano de la función target, y la forma usual en SMath de construirlo es primero calcularlo y guardarlo en una etiqueta cualquiera (Jx en este caso) para luego decir que en realidad es una función de la variable x ( es decir: escribir J(x) = x ).
Con estos elementos ya puedes construir la función "f" que aparece en mathcad.
Se podría poner directamente
. f( PzSb ) = al_nleqsolve(guess,target)
y funcionaría en teoría, pero en la práctica es muy lenta, por lo cual hay que pasarle el jacobiano para que funcione más rápido, y quedaría
. f( PzSb ) = al_nleqsolve(guess,0,ε,target,J)
Pero como lo que interesa es llamarla recursivamente para calcular cientos de valores de Pas, Psb, a medida que te alejes del guess inicial le va a costar más trabajo encontrar las raíces, así que mejor pasas 'guess' también como argumento de f, así emplea las raíces previamente encontradas, que se supenen mejores aproximaciones de la raíz real que el valor inicial de guess.
Finalmente, para valores de PzSb que no encuentra solución, porque probablemente no la haya, en mathcad usas 'NaN', pero pasan dos cosas: SMath no tiene NaN, y además al_nleqsolve no retorna un error, sino que retorna un valor, pero que no se parece a una raíz. Así que en vez de 'NaN', la función f(PzSb,guess) lo que hace es verificar que normi(target(sol))<sqrt(ε), es decir, el máximo de los valores de sol, que son Pas, Psb, sea menor que sqrt(ε), es decir, que se parezca a una solución del sistema de ecuaciones.
Espero haber podido explicar el procedimiento.
Saludos cordiales.
____________________________________
English translation:
Hi Pedro. Yes, there are several "technical" details, for say something.
Let's see if these comments explain a little the solution.
I called it "target" because it is the name that is usually given to the function that you want to optimize. If you look at the way it's solved in Mathcad, the given / find block results in a function, not the root values. This is because you have a system with 3 unknowns and 2 equations: f ( PzSb ) = Find( Pas, Psb ). The target function would not be that "f", yet.
On the other hand, the function al_nlesolve becomes very slow if it is not given the Jacobian of the target function, and the usual way in SMath to build it is to first calculate it and store it in any label (Jx in this case) and then say that it is actually a function of the variable x ( ie: write J(x) = x ).
With these elements you can now build the function "f" that appears in mathcad.
Could be put directly
. f( PzSb ) = al_nleqsolve(guess,target)
and it would work in theory, but in practice it is very slow, so you have to pass the Jacobian to make it work faster, and it would be
. f( PzSb ) = al_nleqsolve(guess,0,ε,target,J)
But since what matters is calling it recursively to calculate hundreds of values ​​of Pas, Psb, as you move away from the initial guess it will take more work to find the roots, so you better pass 'guess' also as an argument to f, like this uses the previously found roots, which are supposed to be better approximations of the actual roots than the initial value of guess.
Finally, for values ​​of PzSb that do not find a solution, because there probably is not, in mathcad you use 'NaN', but two things happen: SMath does not have NaN, and also al_nleqsolve does not return an error, but rather returns a value, but that it doesn't look like a root. So instead of 'NaN', the function f(PzSb,guess) checks that normi(target(sol))<sqrt(ε), that is, the maximum of the values ​​of sol, which are Pas , Psb, is less than sqrt(ε), that is, it looks like a solution of the system of equations.
I hope I was able to explain the procedure.
Best regards.
Alvaro