Errors when plotting but not when evaluating

  • Topic: Mathematica 
  • Thread starter member 428835
  • Start date
  • Tags Tags
    Errors Plotting
3 replies · 2K views · last reply
member 428835
Hi PF!

Attached is a screenshot of my code:
Mathematica notebook code defining a piecewise hat function phi[x, k, h], its derivative, the stiffness matrix K[h], the function f[x] = 27 pi^2/4 Sin[3 pi/2 x], F[h], alpha[h] = Inverse[K[h]].F[h], and a Plot line at In[21].

The issue I'm facing is not being able to plot at line 21. It's weird because when I evaluate ##\alpha[1/4]## on it's own line I instantly receive a 5X1 vector. When I evaluate the Table[##\phi##] statement also shown in line 21 on it's own line I receive instantly a 5X1 vector too. Then when I copy-paste these results and dot them into each other I instantly get a good answer. So why can I not do this on the same line?

On line 21, I've tried changing the ##x## variable in ##\phi## to a ##z## and plotting in ##z##, but it takes so long to run this way. I've also tried evaluating ##\alpha## since this seems to be the issue, but again no luck.

Any help would be awesome!
 
Attachments
  • Mathematica notebook code defining a piecewise hat function phi[x, k, h], its derivative, the stiffness matrix K[h], the function f[x] = 27 pi^2/4 Sin[3 pi/2 x], F[h], alpha[h] = Inverse[K[h]].F[h], and a Plot line at In[21].
    Screen Shot 2018-03-13 at 1.07.00 PM.png
    25.2 KB · Views: 1,042
I'm not sure, but it could be because it is trying to evaluate ##\phi## using a numerical value for ##x##. Try and see if the following helps:
Code:
Plot[\[Alpha][1/4].Table[\[Phi][xx, k, 1/4], {k, 1, 1/1/4 + 1}] /.
  xx -> x, {x, 0, 1}]
 
DrClaude said:
I'm not sure, but it could be because it is trying to evaluate ##\phi## using a numerical value for ##x##. Try and see if the following helps:
Code:
Plot[\[Alpha][1/4].Table[\[Phi][xx, k, 1/4], {k, 1, 1/1/4 + 1}] /.
  xx -> x, {x, 0, 1}]
Yea I tried this but it takes a ridiculous amount of time. Much longer than if I compute manually and then take the dot product. I'm glad I tried this first though! Makes me think I am doing something right!