Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.7K Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Defining a function from expression containing parameters

Posted 2 years ago

As the title says, I've been trying to define a function this way:

f[a_, b_, c_, d_] := 
  Max[rootsFinal[[1]] /. a1 -> a  /. b1 -> b /. c1 -> c, d1-> d];

here rootsFinal[[1]] is a list that contains rational expressions in $a,b,c,d$. The definition seems to succeed, but when I try to call

f[1,1,1,1]

I get the error

"Part specification rootsFinal[[1]] is longer than depth of object"
POSTED BY: Alex Bailey
4 Replies
Posted 2 years ago

I need to compute f on a "grid" with many values of $a,b,c,d$. Thanks for the advice

POSTED BY: Alex Bailey

Are a,b,c,d all parameters? Then what is the main variable? If a,b,c,d are indeed the final variables, I see nothing wrong with your definition, except that it will work only in a session where you have already calculated rootsFinal. If you need a function that works across sessions, you may want to paste the whole expression of rootsFinal[[1]] into the definition of f.

POSTED BY: Gianluca Gorni
Posted 2 years ago

That was it, feeling dumb now. Is this the correct way to make a function out of an expression dependent on parameters or is there a better way? I will have to compute it on a grid of values

POSTED BY: Alex Bailey

Had had closed the session in the meanwhile? That would explain why rootsFinal is not recognized any more.

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