Group Abstract Group Abstract

Message Boards Message Boards

Find root not working when attempting on function defined by module

POSTED BY: david baughman
5 Replies
POSTED BY: Daniel Lichtblau

The NumberQ WORKED!!! THANK YOU SOOO MUCH!!! I WAS BANGING MY HEAD ON THIS FOR 2 DAYS!!!!

POSTED BY: david baughman
Posted 11 years ago
POSTED BY: Bill Simpson
Here is the code cleaner.  Sorry about that:

ClearAll
    SetAttributes[{vhat, khat, w, c, xin, \[Delta], v, j}, Constant]
    khat = .162
    xin = .028
    vhat = .017

Clear[yOUT, yIN, ytest, nIN, nOUT, WronsFUN, \[Lambda], w]
WronsFUN[\[Lambda]_, w_, xoo_] := Module[{val}, Clear[nIN, nOUT];
  nIN = NDSolve[{\[Lambda] == -I*w*x^(3/2) - vhat*x/y[x]*y'[x] - 
       7/2*khat*x^2/y[x]*y'[x] - khat*x^3/y[x]*y''[x], 
     vhat*xin^(-1/2)*y[xin] + khat*xin^(3/2)*y'[xin] == y[xin], 
     y[xin] == 1}, y[x], {x, xin, 1}];
  yIN[x_] = First[y[x] /. nIN];
  nOUT = NDSolve[{\[Lambda] == -I*w*x^(3/2) - vhat*x/y[x]*y'[x] - 
       7/2*khat*x^2/y[x]*y'[x] - khat*x^3/y[x]*y''[x], 
     vhat*y[1] + khat*y'[1] == -y[1], y[1] == 1}, y[x], {x, xin, 1}];
  yOUT[x_] = First[y[x] /. nOUT];
  val = yIN[xoo]*yOUT'[xoo] - yOUT[xoo]*yIN'[xoo]; val]

FindRoot[WronsFUN[j, 21.67, .038], {j, .1 - .1*I}]

WronsFUN[7.07812 - 1.98627*I, 21.67, .038]
POSTED BY: david baughman

You really should reformat so that input is clearly demarcated and easy to cut and paste. Also you might do better by making the function a "black box" that only evalautes on explicit numeric input. This can be done like so.

WronsFUN[\[Lambda]_?NumberQ, w_?NumberQ, xoo_?NumberQ] := ...

Don't forget to first Clear that function so as to remove the existing definition.

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