Simply create a function and put it in an m-file with the same name as your function. For example, for your squaring function chose a name like "Xsquared" for your function and store the function in a file called Xsquared.m. The function code in this m-file would look as follows in this case.Hi. How is it possible to write an equation for example f=X^2 so that anywhere in my code I can get the value of f for a given X by typing
F(X)
for some X value?
Thanks
function [output_value] = Xsquared(x)
output_value = x^2;
end