Post Reply 
Numerical integration
02-03-2016, 06:39 PM
Post: #8
RE: Numerical integration
Perhaps you mean something like:
Code:

#cas
simpsonint(g,a,b,n):=
BEGIN
local l,l1;
IF even(n) THEN
IF (type(g)==DOM_SYMBOLIC  OR type(g)== DOM_FUNC)
  THEN 
   l:=MAKELIST(X,X,a,b,(b-a)/n);
     IF type(g)==DOM_SYMBOLIC THEN
     g:=unapply(g,x);
     END;
   l:=apply(g,l);
   l1:=MAKELIST(even(X)+1,X,1,n+1);
 return (2*DOT(l,l1)-g(a)-g(b))*(b-a)/(3*n);
   ELSE return ("f must be symbolic or function!");
  END;
 // return 0;
ELSE return "n must be even!";
END;

END;
#end


#cas
trapezregel(g,a,b,n):=
BEGIN
local l;
IF (type(g)==DOM_SYMBOLIC  OR type(g)== DOM_FUNC)
  THEN 
   l:=MAKELIST(X,X,a,b,(b-a)/n);
     IF type(g)==DOM_SYMBOLIC THEN
     g:=unapply(g,x);
     END;
   l:=apply(g,l);
   return (2*ΣLIST(l)-g(a)-g(b))*(b-a)/(2*n);
   ELSE return ("f must be symbolic or function!");
  END;
END;
#end


#cas
rightsum(g,a,b,n):=
BEGIN
local l;
IF (type(g)==DOM_SYMBOLIC  OR type(g)== DOM_FUNC)
  THEN 
   l:=MAKELIST(X,X,a,b,(b-a)/n);
     IF type(g)==DOM_SYMBOLIC THEN
     g:=unapply(g,x);
     END;
   l:=apply(g,l);
   return (ΣLIST(l)-g(a))*(b-a)/n;
   ELSE return ("f must be symbolic or function!");
  END;
END;
#end

#cas
leftsum(g,a,b,n):=
BEGIN
local l;
IF (type(g)==DOM_SYMBOLIC  OR type(g)== DOM_FUNC)
  THEN 
   l:=MAKELIST(X,X,a,b,(b-a)/n);
     IF type(g)==DOM_SYMBOLIC THEN
     g:=unapply(g,x);
     END;
   l:=apply(g,l);
   return (ΣLIST(l)-g(b))*(b-a)/n;
   ELSE return ("f must be symbolic or function!");
  END;
END;
#end

EXPORT NumericIntegr()
BEGIN
local a,N,f,b;
N:=12; a:=1;b:=3;
f:='X^2';
   if input(
     {{f,[8],{20,70,0}},
     {a,[0],{20,30,1}},
     {b,[0],{20,30,2}},
     {N,[0],{20,30,3}}},
     
     "Enter Data",
     {"f(X)=", "a= ", "b= ","N= "
      },
     {
       "Enter the function, upper case X!",
       "Enter the starting point",
       "Enter the endpoint",
       "Enter the amount of intervals"
      
     },
     {f,a,b,N}
   )
then
f:=lower(string(f));
PRINT();
PRINT("Simpsonsumme:   "+simpsonint(f,a,b,N));
PRINT("Trapezsumme:    "+trapezregel(f,a,b,N));
PRINT("Rechtecklinks:  "+leftsum(f,a,b,N));
PRINT("Rechteckrechts: "+rightsum(f,a,b,N));
return 
end;
END;
but I did not implement an adaptive method.
Arno
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Numerical integration - alealessietto - 02-03-2016, 04:52 PM
RE: Numerical integration - DrD - 02-03-2016, 04:55 PM
RE: Numerical integration - alealessietto - 02-03-2016, 05:03 PM
RE: Numerical integration - DrD - 02-03-2016, 05:17 PM
RE: Numerical integration - alealessietto - 02-03-2016, 05:30 PM
RE: Numerical integration - DrD - 02-03-2016, 05:38 PM
RE: Numerical integration - alealessietto - 02-03-2016, 05:55 PM
RE: Numerical integration - Arno K - 02-03-2016 06:39 PM
RE: Numerical integration - ndzied1 - 02-03-2016, 08:32 PM
RE: Numerical integration - retoa - 02-04-2016, 10:22 AM
RE: Numerical integration - ndzied1 - 02-04-2016, 11:04 AM
RE: Numerical integration - retoa - 02-04-2016, 12:31 PM



User(s) browsing this thread: