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 = 1024
x = 0:h:1 %discretizations
But 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.
f(something), inside the the function,f, the variable is known assomethingcontaining the argument you passed tof, but when you callf, you may pass the name of any variable you have already used/defined. So you may callf(x)orf(y)orf(whatever)as long asx,y, orwhateverhave been defined. Variable names in MATLAB are not shared between functions unless they are explicitly made global using the global keyword. – Bill Barth Dec 30 '12 at 04:02