I put your function into matlab and there are a couple of issues, I'll start with your specific question then go from there:
-The error 'undefined function or variable 't'.' means that matlab does not know what value 't' is. You must define a value for 't' somewhere outside of the function (in the .m file) before you call the function. Example, if I have this code:
function yahooanswers
ans = chicken(t)
function[x]=chicken(p)
x = p + 2;
end
end
In my code I have used the function 'chicken' and I have told it, use 'chicken' with input 't'. But I have not told it what 't' is, so it will give me the same error you receive. To get the correct answer I must define 't' in my code, outside of the function, thus:
function yahooanswers
t = 2;
ans = chicken(t)
function[x]=chicken(p)
x = p + 2;
end
end
Now that matlab knows 't=2', when I call my function with input 't' it will run the function with this input and return 'ans = 4'. (you know, cuz 2+2=4)
Something else to be wary of, your function definition format is not entirely correct. Instead of using square brackets ' [ ] ' you are using round brackets ' () ' to define your outputs. Matlab won't recognize this. The format to define the function should be:
function[x,y] = funcname(a,b,c,d)
And to Call it:
[ans1,ans2] = funcname(w,x,y,z)
Also, it is unclear what you are attempting to do at the line: x=(xinit zeros (1,n)) because 'n' is not defined in your function name, but I assume it's your intended number of steps. I can tell you that your formatting will cause an error, even if 'n' is defined. Firstly, when defining arrays you must use square brackets. x = [ M N ] Secondly, you can't have a space between 'zeros' and (1,n).
Also, in the beginning of your comment that 'h' is your stepsize, therefore 'n' should be the number of steps you want to take. When you call your function you are calling 'n' as a 0.1 which will create an error since your number of steps must be an integer.
That is the most I can deduce until the above errors are corrected since I am not completely certain of your variable selection. Good luck! This class is a pain, hope you do well.