1

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!

LazyGamer
  • 15
  • 2

2 Answers2

2

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.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
1

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];
e.doroskevic
  • 5,959
  • 1
  • 13
  • 32