MATLAB: Function, input number, return a value

functioninput

QUESTION:
Write a small function which takes as inputs; a number a and a function g(x), and returns (a, g(a)). Note that printing is not the same as returning a value. Use the function g(x) = 2x 2 and a = 4 to test your function.
So my function right now looks like this.
function [a g(x)] = mysmallfunction(x)
a = x;
g(x) = 2*x.^2;
end
And I'm calling it like this:
clear;
[a g(x)] = mysmallfunction(4)
I get the error "Undefined function or variable 'mysmallfunction'."
But also I'm using a specific equation in 2x^2. How do I make it work for any equation.

Best Answer

Your tutor must have taught you about function handles for you to solve this problem.
As per the question, the function you have to write takes two inputs, a number and a function (see function handles) and returns two outputs, the original number and another number. Therefore you must have two variable names before the = in your function declaration and two variable names in the brackets of your function declaration.
Note that g(x) is not a valid variable name.
To get you started, the following declaration would work:
function [a, ga] = mysmallfunction(x, g)