0
$\begingroup$

Suppose v[w,y] is a function and consider the following solution for w:

solw = Solve[v[w,y]==0,w,Reals];
w[y]:= N[w/.solw]

I need to use w[y] in a number of other calculations before I substitute in a value for y. However, if I substitute a value for y in at this point, the resulting list contains Undefined elements, e.g.: w[y]/.y->20 yields:

{-2.53, -1.534,23.2,Undefined,Undefined}

The last two elements screw up my future calculations. As a very simple example (not the one I am working on, but simple enough to present here), suppose I want to compute:f[y]=w[y]^2 + 2y. Is there a way to define w[y] now so that the undefined elements are dropped from the list in any future calculations such as f[y]? For the specific problem I am working on, it would be MUCH easier to deal with this problem BEFORE computing f[x]. Thanks!

$\endgroup$
  • 2
    $\begingroup$ list /. Undefined -> Nothing might do it. $\endgroup$ – Michael E2 May 7 at 14:56
  • 1
    $\begingroup$ DeleteCases[list, Undefined] or Select[list, NumericQ] should do the trick. $\endgroup$ – Sjoerd Smit May 7 at 15:05
  • $\begingroup$ Thanks. These work when I apply them after having first evaluated the function at a particular value of y, but not when i evaluate the value of y later. $\endgroup$ – Rick May 7 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.