MATLAB: How to make MatLab output unassigned variables

Symbolic Math Toolboxvariables

I'm used to Mathematica, so I'm not sure how and if the same works with MatLab. Is there a way to input something like:
x = 3t
and have x be equal to 3t until you assign t a value?
edit:
so I have this code:
function [zr,w,R,q,mat] = test(z)
lambda = 1;
w0 = 1;
zr = (pi*w0^2)/lambda;
w = w0*sqrt(1+(z/zr)^2);
R = z + zr^2/z;
q = z + 1i*zr;
mat = [1 z; 0 1];
end
but I not want to have to assign lambda and w0, i want them to just stay lambda and w0 UNLESS I assign them … so inputting
[zr,w,R,q,mat] = test(z)
should return the variables exactly how they look inside the function:
zr =
(pi*w0^2)/lambda
w =
w0*sqrt(1+(z/zr)^2)
R =
z + zr^2/z
q =
z + 1i*zr
mat =
1 z
0 1
also, how come these don't exist outside of the function? I can't call q anymore for example after executing test because it doesn't appear to exist anymore

Best Answer

If I remember correctly, Mathematica is primarily a symbolic language. The most direct way to emulate Mathematica in MATLAB is to use the MATLAB Symbolic Math Toolbox.
For example:
syms x(t)
x(t) = 3*t;
xt = x(t)
t = 9;
xt = x(t)
produces:
xt =
3*t
xt =
27