Message Boards Message Boards

0
|
2111 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Syntax Problem?

Posted 10 years ago

Is somebody able to explain why line 87 works and 85 does not?
enter image description here

POSTED BY: Jakob Teuffel
3 Replies
Posted 10 years ago

Hi thanks for the fast Answer Evaluate@ seems to do do the trick. Sorry for the Picture next time I'll post the code. So when do I have to put an Evaluate@ in this situation the problem seems to be at the Integrals.

POSTED BY: Jakob Teuffel

Hi,

well, yes. In particular I think that the integration variable of the integrals causes problems. Because of the delayed evaluation it leaves the Integrals as they are. When you plot wrt x then that causes a problem. If you rename the integration variables you also circumvent the problem (but the whole thing gets very slow):

a[n_] := (\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(-1\), \(1\)]\(
\*SuperscriptBox[\(Sin[
\*FractionBox[\(Pi\ n\), \(2\)] y]\), \(2\)] \[DifferentialD]y\)\))^-1

b[n_] := (\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(-1\), \(1\)]\(
\*SuperscriptBox[\(Cos[
\*FractionBox[\(Pi\ n\), \(2\)] y]\), \(2\)] \[DifferentialD]y\)\))^-1

\[Phi]odd[x_, n_] := b[n] Cos[(Pi n)/2 x]

\[Phi]even[x_, n_] := a[n] Sin[(Pi n)/2 x]

\[Psi][x_, \[Alpha]_, \[Beta]_] := -\[Alpha] \[Phi]odd[x, 
    1] + \[Beta] \[Phi]even[x, 2]

Plot[{\[Psi][x, 2^-0.5, 2^-0.5], \[Psi][x, 
   3^-0.5, (2/3)^-0.5]}, {x, -1, 1}]

will give the correct plot with no error messages, but it will run for a while.

Cheers,

M.

POSTED BY: Marco Thiel

Hi,

I guess that the problem is the delayed evaluation of $\psi$. (BTW, it is quite cumbersome to retype everything if you paste an image into your post. The code would be much easier to debug.

a[n_] := (\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(-1\), \(1\)]\(
\*SuperscriptBox[\(Sin[
\*FractionBox[\(Pi\ n\), \(2\)] x]\), \(2\)] \[DifferentialD]x\)\))^-1

b[n_] := (\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(-1\), \(1\)]\(
\*SuperscriptBox[\(Cos[
\*FractionBox[\(Pi\ n\), \(2\)] x]\), \(2\)] \[DifferentialD]x\)\))^-1

\[Phi]odd[x_, n_] := b[n] Cos[(Pi n)/2 x]

\[Phi]even[x_, n_] := a[n] Sin[(Pi n)/2 x]

\[Psi][x_, \[Alpha]_, \[Beta]_] := -\[Alpha] \[Phi]odd[x, 
    1] + \[Beta] \[Phi]even[x, 2]

As you say, if you plot

Plot[{\[Psi][x, 2^-0.5, 2^-0.5], \[Psi][x, 3^-0.5, (2/3)^-0.5]}, {x, -1, 1}]

that does not work. You can either prefix everything with Evaluate:

Plot[Evaluate@{\[Psi][x, 2^-0.5, 2^-0.5], \[Psi][x, 3^-0.5, (2/3)^-0.5]}, {x, -1, 1}]

or modify the definition of $\psi$ like so:

\[Psi][x_, \[Alpha]_, \[Beta]_] = -\[Alpha] \[Phi]odd[x, 1] + \[Beta] \[Phi]even[x, 2]

Now, it's not a delayed definition anymore. Now the plot command works without the Evaluate.

Cheers,

Marco

Attachments:
POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract