1
$\begingroup$

I have the following code:

c[theta_, xi_] = theta*xi + theta^xi^2; xbar[theta_, xi_] = theta/xi + xi^2 + theta^3; f[x_, y_, theta_, xi_] = x*y*c[theta, xi]*theta*xi + xbar[theta, xi]; 

That is, I would like to define $f$ as a function $x,y,theta,xi$ using two predefined functions $c$ and $xbar$. But mathematica gives tag times is protected. How to deal with it? Many thanks!

$\endgroup$
1
  • $\begingroup$ Evaluate Remove[c, xbar, f] before the function definitions. $\endgroup$ Commented Jan 30, 2016 at 21:00

2 Answers 2

2
$\begingroup$

You need to make sure there are no active definitions on the constituent parameters. You can do this with ClearAll as E.Doroskevic proposes, though I imagine you will not want to clear all Global` definitions.

You can Block the Symbols in use as described in Scoping in assigning a derivative. To make this convenient I propose using the function localSet which I wrote for How to make a function like Set, but with a Block construct for the pattern names.

xi = "fail!"; y = "bad!"; localSet[c[theta_, xi_], theta*xi + theta^xi^2] localSet[xbar[theta_, xi_], theta/xi + xi^2 + theta^3] localSet[f[x_, y_, theta_, xi_], x*y*c[theta, xi]*theta*xi + xbar[theta, xi]] ?f 

Global`f

f[x_, y_, theta_, xi_] = theta^3 + theta/xi + xi^2 + theta x xi (theta^xi^2 + theta xi) y

Observe that the definition is correct despite the definitions on xi and y.

$\endgroup$
1
$\begingroup$

Try:

ClearAll["Global`*"] c[theta_, xi_] = theta*xi + theta^xi^2; xbar[theta_, xi_] = theta/xi + xi^2 + theta^3; f[x_, y_, theta_, xi_] = x*y*c[theta, xi]*theta*xi + xbar[theta, xi]; 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.