TransWikia.com

Lists{vals,funs} and NDEigensystem are not the same shape?

Mathematica Asked by AstrophysicsAmy on February 13, 2021

Hi I’m trying to create a Manipulate[Plot[]] so that I can vary lambda in the below equation from 0 to 2 and see how it affects my plot. I’m getting stuck a couple steps before that though where I use NDEigensystem to solve a potential. It keeps giving the error,

Set::shape: Lists {vals,funs} and NDEigensystem[29.1667 (E^(-0.261861x) - 2E^(-0.130931x) + E^(-0.0872872x) * [Lambda]) * u[x]-u''[x]/2,u[x],{x,-29.1667 (25.9352 exp+6177.79 * [Lambda]),100},1,Method->{SpatialDiscretization->{FiniteElement,{MeshOptions->{<<1>>}}}}] are not the same shape.

Here is the code I’m using that’s giving me the error:

V[x_] := 7/(48(.005)) (E^(-2[x]/7.637626158259733) - 
    2 E^(x/7.637626158259733) + [Lambda]*E^(-2/3 x/7.637626158259733))
[L] = -h^2*u''[x] + V[x]*u[x]; {vals, 
  funs} = NDEigensystem[[L], 
  u[x], {x, -29.166666666666668 (2.357747434867739*
       exp(11) + 6177.788320394612 * [Lambda]), 100}, 1, 
  Method -> {"SpatialDiscretization" -> {"FiniteElement", 
{"MeshOptions" -> {MaxCellMeasure -> 0.01}}}}];

And here is the follow-up code that I’m trying to use to plot it all:

In[42]:= vals

Out[42]= vals

Manipulate[Show[Plot[Evaluate[h*funs + vals], {[x], -10, 10}, 
   BaseStyle -> {FontWeight -> "Bold", FontSize -> 12}, 
   AxesLabel ->{"x","V(x)"}, PlotPoints->1000, PlotStyle->{Thickness[0.009]}],Plot[V[x],{x,0.5,60},BaseStyle->{FontWeight->"Bold",FontSize->12},AxesLabel->{"x","V_(x)"},PlotPoints->1000,PlotStyle->{Thickness[0.009]}],PlotRange->{{0.5,60},{0.4}},AxesOrigin->{-5,0},ImageSize->Medium],{Lambda,0,2}]

I also provided a screenshot of the code I am basing this off of which worked fine for me, I think it’s just because of the constant lambda I now have? I am also assuming that this is the reason there’s nothing showing up for my Manipulate[Plot[]] so ideally if we can fix this shape issue then everything else should be good…I hope.

Side note: I already defined h above the error-producing code (in the nice error-free code; see image) which is why it’s not shown in the bad error code.

Thanks for any help!!
Note: the top code is the code I’m basing this off of and the bottom code is my current code that’s failing me.
Code that works beautifully for same exact style of equation

Bad Code

One Answer

This produces some plots, but it's not exactly what you're asking for. (I changed the interval for NDEigensystem to {x, -30, 30} to avoid crashing)

Clear[L, V]
h = 1/Sqrt[2];

V[x_, lambda_] := 
 7/(48 (.005)) (E^(-2 x/7.637626158259733) - 
    2 E^(x/7.637626158259733) + lambda*E^(-2/3 x/7.637626158259733))

L[lambda_] := -h^2*u''[x] + V[x, lambda]*u[x]

f[lambda_] := 
 NDEigensystem[L[lambda], u[x], {x, -30, 30}, 1, 
  Method -> {"SpatialDiscretization" -> {"FiniteElement", 
{"MeshOptions" -> {MaxCellMeasure -> 0.01}}}}]

Manipulate[
 {funs, vals} = f[lambda];
 Show[
  Plot[h*funs + vals, {x, -10, 10}, AxesLabel -> {"x", "V(x)"}, 
   PlotStyle -> Red, PlotPoints -> 1000],
  Plot[V[x, lambda], {x, 0.5, 60}, PlotStyle -> Blue, 
   PlotPoints -> 1000],
  PlotRange -> {{0, 10}, {-5, 10}}
  ],
 {lambda, 0.1, 2}]

enter image description here

Correct answer by MelaGo on February 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP