Let me first state that I am a Mathematica novice and this question is probably easily answered, but I have so far not been able to find any help for this specific problem scouring the internet. Here, I've basically summarized what I need my code to do. There is some problem using the /.
replace command with the IF
conditional statement. Basically, I have a very long function which contains another function which is defined globally by an IF
conditional. These few lines of code demonstrate the error I am running into...
In[1]:= y[x_, z_] = 2*x + 3*z;
In[2]:= zz[x_, z_] := If[y[x, z] < 0, 4*y[x, z], y[x, z]]
In[3]:= zz[-1, -2]
Out[3]= -32
But I need...
In[4]:= zz[x_, z_] /. x -> -1 /. z -> -2
Out[4]= If[3 Pattern[-2, _] + 2 Pattern[-1, _] < 0,
4 y[Pattern[-1, _], Pattern[-2, _]],
y[Pattern[-1, _], Pattern[-2, _]]]
which does not yield the expected numeric term. Thanks in advance to all of you for your help, despite how silly this question may sound. Note: I must use the replace command as opposed to directly assigning a value to x
and z
.
ADDENDUM:
I simplified my example too much. Take this example:
In[91]:= a[b_, c_] = -3*b + 2*c + d + e + f;
In[92]:= g[b_, c_] := If[a[b, c] < 0, -3*a[b, c], a[b, c]];
In[10]:= g[2, 4] /. d -> 1 /. e -> 2 /. f -> 3
Out[10]= 2 + d + e + f
But I expect to see the result Out[10]= 8
Hopefully another easy fix.