function [output1,...,outputN] = myfun(input1,...,inputM)
Otherwise you may notice the following error message:
Error: Function definitions are not permitted in this context.
$f(x) = x^2 -1$
open func1.m
function y=func1(x)
y=x.^2 - 1;
end
func1(2)
func1([1 2 3])
open func2.m
function [p, q]=func2(x,y)
p=x.^2+y.^2;
q=x+y;
end
[p1,q1]=func2(2,3)
A = [1, 2]; B = [2, 3];
[p2, q2] = func2(A,B)
A = [1, 2; 3, 4]; B = [2, 3; 4, 5];
[p3, q3] = func2(A,B)
function [p, q]=func2(x,y)
p=x.^2+y.^2;
q=x+y;
end
phi = @(x, y) x+y;
phi(0,2)
phi([0 1],[2 3])
phi([0 1; 2 3],[2 3;4 5])
function f = fact(n)
f = prod(1:n);
end
fact(5)