cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Least Squares

ralphyp
1-Newbie

Least Squares

I am trying to evaluate a Jacobian Matrix and I keep getting zeros for an answer. Help.
20 REPLIES 20
RichardJ
19-Tanzanite
(To:ralphyp)

Could you change the file name to get rid of the #. This forum doesn't like certain characters in file names (try downloading it).

Richard

No Problem

Sorry Here it is again
RichardJ
19-Tanzanite
(To:ralphyp)

Available numeric values are substituted and then the result is passed to the symbolic processor. So you are effectively taking the derivative of a number w.r.t. a number, which is zero. Disable all of the numeric assignments at the top of the sheet. You will see a lot of red, but that's just the numeric processor complaining. Ignore it, because the symbolic processor doesn't care. Then you will see your (very large) Jacobian.

Richard

How can I get it to evaluate it numerically? I must be missing something.

Ralph

On 2/21/2009 9:05:00 PM, ralphp wrote:
>How can I get it to evaluate
>it numerically? I must be
>missing something.
>
>Ralph
____________________________

I can't relate the thread "Last Squares" to the material in the work sheet. It you have a set of paired values X, Y you can get the least square fit of order 'n', directly from very simple matrix operations. What is that Jacobian doing ?

Let's flip the pancake :

Do you have data set to fit ?
If yes, attach in a new work sheet.

jmG

You need to understand a bit more about Mathcad's numeric and symbolic processors.

When you make an assignment (:=) what is assigned is the result of evaluating the right hand side, with all defined variables replaced by their definitions. This is true for both the numeric and symbolic processors. For the symbolic processor undefined variables remain in the assigned value as free variables. For the numeric processor undefined variables result in an error. The only way to make a definition for the numeric processor that includes an expression that can be evaluated with different values is to make a function.

You cannot differentiate a constant (at least, not meaningfully). Differentiation in Mathcad is the differentiation of an expression (not a function) with respect to a variable that appears in the expression. For the numeric processor the variable must appear literally, it cannot be introduced by substitution of defined values (values for the numeric processor not allowing free variables). For the symbolic processor the variable can appear literally in the expression, or may be brought in by substitution (but not in MC13.1, where that is broken). The expression can be, and often is, as simple as a function name applied to some set of variables, including the variable of differentiation.

The numeric and symbolic values for a variable need not be the same, and it is possible for either to be defined without the other. The idiom x:=x will cause x to be undefined to the symbolic processor, but retain its previous definition for the numeric processor.

The attached sheet shows one way to get a symbolic solution, and to be able to evaluate that symbolic solution numerically. It works well in MC11, less so in MC14. MC14 is very slow on this problem (the symbolic processor in MC14 is generally quite slow), and produces results that are too big for MC14 to be willing to display.

Note that if you look through this collaboratory you will find a number of tool boxes available. The Jacobian etc. sheet does all manner of multivariate differentiation. The routines have been copied into the attached sheet, but the documentation is just in the Jacobian etc. work sheet.

I don't know what you want the Jacobian for. But if you are planning some sort of Newtonian iteration, it won't work anyway. For that you must use functions so that you can reevaluate the Jacobian at each iteration, using the then current guess values. It is also generally pointless to code a Newtonian iteration. A solve block will usually do the job a lot easier and a lot faster.
__________________
� � � � Tom Gutman

Thank You Tom and others and yes you are correct, this will require iterations.

Ralph

On 2/22/2009 5:25:54 AM, ralphp wrote:
>Thank You Tom and others and
>yes you are correct, this will
>require iterations.
>
>Ralph
_______________________________

You have two keywords w/o details
1. "Least squares:
2. "Iterations"
Attached is my resulting understanding.
MCD 13, 14 don't administrate Deriv wrt.
Genfit has been in the collab within last 2 wks

jmG



>When you make an assignment (:=) what is
>assigned is the result of evaluating the right
>hand side, with all defined variables replaced
>by their definitions
Not so simple. One picture:

I think Mathcad needs an order in the using of numerical and symbolic Math. Can we mix? Where is documenter rules etc.
Val
http://twt.mpei.ac.ru/ochkov/v_ochkov.htm

Your picture shows that symbolically evaluating b²/b results in just b. Not particularly surprising.
__________________
� � � � Tom Gutman

On 2/22/2009 4:21:43 PM, Tom_Gutman wrote:
>Your picture shows that
>symbolically evaluating
>b�/b results in just b.
>Not particularly surprising.
>__________________
>� � � � Tom Gutman
My picture shows that a variable in Mathcad can keep not only numerical value (pure Mathcad) but simbolical value too (as in Maple, Mathematica, MuPAD etc) and this it is not documented.
I thhink in Mathcad 15 with new symbolic engine (MuPAD now is full in Matlab) this will be documented or blocked.

Val
http://twt.mpei.ac.ru/ochkov/v_ochkov.htm

That has always been documented as part of symbolic evaluation. Undefined variables represent themselves.

What is not documented, but not shown by your picture, is that it is possible for a numeric value (i.e., a value used by the numeric processor and displayed with the numeric evaluation operator 😃 to be an expression. This was used in MC11 by find, to allow the return of values with different units. In later versions find no longer does that (a definite loss of functionality), but the underlying capability seems to still be there, at least in MC13.
__________________
� � � � Tom Gutman

On 2/23/2009 4:46:15 AM, Tom_Gutman wrote:

>That has always been
>documented as part of symbolic
>evaluation.
Sorry, I have seen only here. Can you show me more!

Val
http://twt.mpei.ac.ru/ochkov/v_ochkov.htm

I figured out a way to formulate my jacobian, I now want to iterate. At the bottom of the attached worksheet you will see my explanation of what I want to do, basically I want to add my delta X's to my X sub zero values until it converges. I'm new to programming and Mathcad so be easy. Feel free to email me any feedback. Xsub zero are my initial approximations. These are Surveying Problems.



Ralph

>I figured out a way to formulate my jacobian, I now want to iterate<<br> ____________________

"Least squares" are not based on Jacobians.
You should describe what you want to achieve.
You will have greater audience "Save as " 11,
or lower versions, unless specific to 13, 14.

jmG

>>"Least squares" are not based on Jacobians.<<

Yes, they are.
__________________
� � � � Tom Gutman

I don't do private consulting (e-mail). I contribute to this public forum as a member.

You can't iterate over a sheet (well, there are some ways to sort of do it, but they are clumsy and unreliable). Any expression you want to evaluate more than once has to be either within a loop or written as a function. The iteration has to be done as a loop, usually a for or while loop in a program structure. You can't just write out a calculation and then iterate it. You have to plan the iteration from the start.

But that is not really appropriate here. Mathcad provides for least squares solutions in a number of ways, the most general being minerr. It solves this problem in just a few lines.
__________________
� � � � Tom Gutman

Thank You Tom and all who have contributed. I did not intend for a private consultation, my apologies if it came across that way. The equation is non linear and I linearized it by taking the partial derivatives. This is by no means a professional endeavor, it is simply a learning exercise. As you can see the solution has already converged after the first iteration. I'm simply trying to learn mathcad and all it's tools, particularly programming. I was trying to figure out how to do this with a "while" loop.





Ralph

>I'm simply trying to learn Mathcad and all it's tools, particularly programming <.
________________________

Programming in Mathcad is particularly simple and difficult. Simple as it comes from all the Mathcad functionalities that can be included in the the program suite. Difficult on the basis of the mathematical construct. The LHS declares the user algorithm, i.e: a user more involved function than erf(x) per say or user functions that construct by themselves on the RHS. A Mathcad program is a maths modules function "compactor". I would be a "compiler" if like in program based systems it would "suite" in machine language. Just figure it's the "Thinker bell Fairy" saying that. "Thinker Bell Fairy = F�e Clochette"

In what you are probably trying to do, you must either have a data set from source or construct one if you have some ground to do so. Whatever, assuming you have the data set, you must plot first and inspect for what is the best representation by either an interpolating approximation like polynomial or a model. The first part of the sheet is a simple LS [Least Squares] polynomial interpolation. The given construct does the LS and involves nothing else. Below Marlett, here is another data set that we can try applying a model to best fit. It is the "Genfit basis" Newton-Gauss algorithm. It's not needed to iterate, it does it on he N included in the program. The entire Mathcad built-in Genfit is not known or at least has never been unveiled. But as you can see it includes the LS call in the function program. Instead of genfit, you could use Minerr, and also you need a set of guess values that will pass the guessed function to cross the data set at least once.
Hope it helps, because I understand nothing in your work sheet. Numerical maths don't start from total scratch, there are lot of basics that you simply accept and try to best use to produce some results.

Watch the User 'a'

jmG

Top Tags