From: Dellia Darlington on 16 May 2010 20:16 I am having problems deciphering the John Mathews and Kurtis D Fink Composite Trapezoidal and Simpson's Matlab Program when I use the program I keep getting function undefined. Can you send me an example on how to use the MATLAB programs. In case you do not know the program the first one is the Simpson and the second the Trapezoidal. function s=simps(f,a,b,M) %Input - f is the integrand input as a string 'f' % - a and b are upper and lower limits of integration % - M is the number of subintervals %Output - s is the simpson rule sum h=(b-a)/(2*M); s1=0; s2=0; for k=1:M x=a+h*(2*k-1); s1=s1+feval(f,x); end for k=1:(M-1) x=a+h*2*k; s2=s2+feval(f,x); end s=h*(feval(f,a)+feval(f,b)+4*s1+2*s2)/3; Function s=trapezoidal(f,a,b,M) %Input - f is the integrand input as a string 'f' % - a and b are upper and lower limits of integration % - M is the number of subintervals %Output - s is the trapezoidal rule sum h=(b-a)/M; s=0; for k=1:(M-1) x=a+h*k; s=s+feval(f,x); end s=h*(feval(f,a)+feval(f,b))/2+h*s;
From: TideMan on 16 May 2010 20:39 On May 17, 12:16 pm, "Dellia Darlington" <delli...(a)live.com> wrote: > I am having problems deciphering the John Mathews and Kurtis D Fink Composite Trapezoidal and Simpson's Matlab Program when I use the program I keep getting function undefined. Can you send me an example on how to use the MATLAB programs. In case you do not know the program the first one is the Simpson and the second the Trapezoidal. > > function s=simps(f,a,b,M) > > %Input - f is the integrand input as a string 'f' > % - a and b are upper and lower limits of integration > % - M is the number of subintervals > %Output - s is the simpson rule sum > > h=(b-a)/(2*M); > s1=0; > s2=0; > > for k=1:M > x=a+h*(2*k-1); > s1=s1+feval(f,x); > end > for k=1:(M-1) > x=a+h*2*k; > s2=s2+feval(f,x); > end > > s=h*(feval(f,a)+feval(f,b)+4*s1+2*s2)/3; > > Function s=trapezoidal(f,a,b,M) > > %Input - f is the integrand input as a string 'f' > % - a and b are upper and lower limits of integration > % - M is the number of subintervals > %Output - s is the trapezoidal rule sum > > h=(b-a)/M; > s=0; > > for k=1:(M-1) > x=a+h*k; > s=s+feval(f,x); > end > > s=h*(feval(f,a)+feval(f,b))/2+h*s; All this is superfluous. What you should have shown us is how you are defining the function and how you are calling these routines. You say the error message you get is "function undefined". Did you spend a moment or two thinking about what this means, and how you could have screwed up? Or did you just assume you must be right and the routines must be wrong, and dash off this post?
|
Pages: 1 Prev: Plot both signal and decimated signal on same axis Next: Class Diagram (e.g. UML, etc) |