Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X
I am trying to calculate the Jacobian (for a Newton Raphson scheme). At this point the problem is simple enough that I can derive it by hand but I want to make sure the two approaches agree (especially since my hand-derived result is nearly singular). What I am doing is not working - I get a "pattern match" error. Worksheet (in MC11) is attached. Thanks for any suggestions.
Solved! Go to Solution.
@JohnRudnicki wrote:
Actually, I am using MC 14 (I posted MC 11 for Luc).
I already suspected that, hence my question.
MC14/15 often behaves differently than MC11. We recently discovered in a thread here that this is especially true for the implementation of sums. In MC14/15 the symbolic evaluation of sums is identical to the numeric one. In MC11 the symbolic evaluation of sums follows a bit more the math standards - a sum from 1 to 0 yields 0, but unfortunately a sum from 1 to -1 should also return 0 but it doesn't. -> Re: Limit value sought - PTC Community
The symbolic evaluation never liked if-statements because the expressions are simplified before any specific values were applied and so the symbolic can't decide which branch to go.
Maybe it helps to define it using the Heaviside function (which fortunately is implemented with Phi(0)=0.5) which the symbolics usually can handle
RHS evaluates symbolically now, but the result is too large to display.
The same may apply to the symbolic evaluation of Jacob(...), but as it seemed to need infinite time to finish I cancelled the operation (I am not a very patient person).
BTW, the second argument (m) of your function "Gvec" is never used in that function. It rather uses the global variable n (=7)
Mathcad 11 doesn't 'know' the Jacob function. I get a symbolic evaluation failure on Gvec:
Tracing back, I see SS fail due to PHI. Noticing that sin(x)/x = sinc(x), try:
then:
and disp will evaluate symbolically as well, but symbolic evaluation of RHS throws another 'must be scalar' problem.
Hope this helps.
Success!
Luc
Thanks for taking a look and for your suggestion. I must be doing something wrong because I get "division by zero" when I try to evaluate SS symbolically. The problem seems to be the first term, but it is ok if I evaluate numerically. I can't figure out what I am doing wrong (updated MC 11 worksheet is attached).
RHS is the problem in the Jacobian. When I try to evaluate it symbolically I get the "pattern match exception" error.
Are you using MC15 or MC11?
In MC15 the sum seems to be implemented somewhat differently as in MC11 - maybe this causes the problem.
Anyway, in MC15 it throws the division by zero error when using the sum (at kk=0) while the expression itself works OK.
So maybe this workaround (for n>1) works for you:
Actually, I am using MC 14 (I posted MC 11 for Luc).
Your suggestion worked. Thanks. And MC also was able to evaluate disp(F,xi,n) symbolically although it took quite a while. That still leaves me with the problem of RHS, which gives me "must be a scalar" when I try to evaluate symbolically. Unless you have some clever suggestion, I think I need to modify the formulation (and I am not sure that RHS enters the Jacobian anyway since Y enters only in the conditional).
@JohnRudnicki wrote:
Actually, I am using MC 14 (I posted MC 11 for Luc).
I already suspected that, hence my question.
MC14/15 often behaves differently than MC11. We recently discovered in a thread here that this is especially true for the implementation of sums. In MC14/15 the symbolic evaluation of sums is identical to the numeric one. In MC11 the symbolic evaluation of sums follows a bit more the math standards - a sum from 1 to 0 yields 0, but unfortunately a sum from 1 to -1 should also return 0 but it doesn't. -> Re: Limit value sought - PTC Community
The symbolic evaluation never liked if-statements because the expressions are simplified before any specific values were applied and so the symbolic can't decide which branch to go.
Maybe it helps to define it using the Heaviside function (which fortunately is implemented with Phi(0)=0.5) which the symbolics usually can handle
RHS evaluates symbolically now, but the result is too large to display.
The same may apply to the symbolic evaluation of Jacob(...), but as it seemed to need infinite time to finish I cancelled the operation (I am not a very patient person).
BTW, the second argument (m) of your function "Gvec" is never used in that function. It rather uses the global variable n (=7)
Thanks for the information.
I suspected the problem was the if statements.
I will see how patient I can be but I think I need to rethink the formulation. I might be back to this.
I still get
when I try to evaluate the Jacobian. so I did not even get the opportunity to be patient. Do I still have something wrong. (I corrected the use of m in Gvec. So it is now used)
Nevermind. Stupid mistake!
You can't evaluate "Jacob" numerically unless you define Y with specific numeric values. You rather will have to use symbolic eval.
Hi @JohnRudnicki,
I wanted to see if you got the help you needed.
If so, please mark the appropriate reply as the Accepted Solution. It will help other members who may have the same question.
Of course, if you have more to share on your issue, please pursue the conversation.
Thanks,
Anurag