Say I have a function function u = somefxn(f,n)where f is some function, say f = pi^2*sin(pi*x), and n is the number of discretizations (let n = 1024) on the interval $[0,1]$. In my code I've written h = 1/n %n = 1024x = 0:h:1 %discretizationsBut what if the user uses y or z in the function instead of x? How do I handle that uncertainty? Please let me know if this isn't clear. I'm rather new to Matlab.
Handling function inputs in Matlab
matlab
The function f has (should have?) its own local variable, the name of which is independent of the calling scope.It's much better to use x = linspace(0,1,n+1) than x = 0:1/n:1 because the latter is susceptible to rounding error.