I have a function $\phi(x,t)$ and I want to define a function $f$ whose values depend on $\phi$. Specifically:
$$f(x,t) = \begin{cases}6\phi(x,t)+1, & \text{if }\phi(x,t) < 0 \\ 2\phi(x,t), & \text{otherwise} \end{cases}$$
In Matlab I tried:
function g = f(x,t)
if phi(x,t) < 0
g = 6*phi(x,t)+1;
else
g = 2*phi(x,t);
end
But it doesn't work. Any advice?
Your code will only work if
phi(x,t)returns a scalar. If it returns a non-scalar array, you'll get an error. And presumably ifxand/ortis non-scalar thenphi(x,t)will have the same dimensions? With that assumption, here is one way you can adapt your function: