Mathematica Errors when plotting but not when evaluating

  • Thread starter Thread starter member 428835
  • Start date Start date
  • Tags Tags
    Errors Plotting
AI Thread Summary
The discussion revolves around a coding issue in Mathematica related to plotting on line 21 of the user's code. The user successfully evaluates two components, ##\alpha[1/4]## and the Table[##\phi##] statement, individually, both returning 5X1 vectors. However, they encounter difficulties when attempting to plot these components together on the same line, leading to performance issues. The user suspects that the problem may stem from Mathematica trying to evaluate ##\phi## with a numerical value for ##x##. Suggestions were made to modify the code to improve performance, but attempts to implement these changes resulted in significantly longer execution times compared to manual calculations. The user expresses uncertainty about the evaluation order in Mathematica, indicating a need for clarity on how to optimize the plotting process.
member 428835
Hi PF!

Attached is a screenshot of my code:
Screen Shot 2018-03-13 at 1.07.00 PM.png

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

  • Screen Shot 2018-03-13 at 1.07.00 PM.png
    Screen Shot 2018-03-13 at 1.07.00 PM.png
    25.2 KB · Views: 981
Physics news on Phys.org
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!
 
It's hard sometimes to know in which order Mathematica is doing things.
 

Similar threads

Back
Top