Group Abstract Group Abstract

Message Boards Message Boards

0
|
17K Views
|
7 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Core language (Tutorial Collection) - pages 98 and 99

Posted 13 years ago
Dear:

Reading the Core Language cited above I typed the following instructions:
 odeplot[de_, y_, {x_, x0_, x1_}, opts : OptionsPattern[]] :=
 
  Module[{sol},
   sol = NDSolve[de, y, {x, x0, x1},
     FilterRules[{opts}, Options[NDSolve]]];
   if[Head[sol] === NDSolve,
    $Failed,
    Plot[Evaluate[y /. sol], {x, x0, x1},
    Evaluate[FilterRules[{opts}, Options[Plot]]]]
   ]
  ]
odeplot[{y''[x] + y[x] == 0, y[0] == 1, y'[0] == 0}, y[x], {x, 0, 10}]

Unfortunatelly it did not work but it worked when I delete the If, as you can see bellow (Plts Attachded):
odeplot[de_, y_, {x_, x0_, x1_}, opts : OptionsPattern[]] :=

Module[{sol},
  sol = NDSolve[de, y, {x, x0, x1},
    FilterRules[{opts}, Options[NDSolve]]];
  Plot[Evaluate[y /. sol], {x, x0, x1},
   Evaluate[FilterRules[{opts}, Options[Plot]]]]
  ]

Could you help me why does not work a simple program from Tutorial Collection ?

Thanks,
Ana
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard
Be respectful. Review our Community Guidelines to understand your role and responsibilities. Community Terms of Use