Numericintegration
12-27-2017, 11:43 PM (This post was last modified: 12-28-2017 05:55 PM by Arno K.)
Post: #1
 Arno K Senior Member Posts: 442 Joined: Mar 2015
Numericintegration
This program uses an hybrid of CAS and Home-program to compute the integral of an via input entered function, the borders and intervals to compute diverse numeric integrals. It can easily be extended to other formulas, the included ones are those I sometimes need to check hand-calculations made by my pupils.
Arno NumericIntegr.hpprgm (Size: 5.85 KB / Downloads: 11)
Edit: Update attachment, now provides exact value, too
12-28-2017, 03:46 PM
Post: #2 Namir Senior Member Posts: 754 Joined: Dec 2013
RE: Numericintegration
Can you please post the listing?

Thanks!

Namir
12-28-2017, 04:20 PM (This post was last modified: 12-28-2017 05:47 PM by Arno K.)
Post: #3
 Arno K Senior Member Posts: 442 Joined: Mar 2015
RE: Numericintegration
Its a little bit long, but here it is:
Code:
 #cas integr(g,a,b):= BEGIN logal h,x; g:=expr(g); IF type(g)==DOM_SYMBOLIC THEN      g:=unapply(g,x);      END; h:=int(g(x),x,a,b); RETURN (h); END; #end #cas simpsonint(g,a,b,n):= BEGIN local l,l1; g:=expr(g); 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; ELSE return "n must be even!"; END; END; #end #cas trapezregel(g,a,b,n):= BEGIN local l; g:=expr(g); 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; g:=expr(g); 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; g:=expr(g); 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,,{20,70,0}},      {a,,{20,30,1}},      {b,,{20,30,2}},      {N,,{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("Simpsonsum:   "+simpsonint(f,a,b,N)); PRINT("Trapezoidsum:    "+trapezregel(f,a,b,N)); PRINT("Rectangleleft:  "+leftsum(f,a,b,N)); PRINT("Rectangleright: "+rightsum(f,a,b,N)); PRINT("Integral:"+integr(f,a,b)); return; end; END;
Arno
Edit: Got that thing with the exact integral implemented, I thought it to be nice to see it for comparing.
12-28-2017, 06:22 PM
Post: #4 Namir Senior Member Posts: 754 Joined: Dec 2013
RE: Numericintegration
Thank you!

:-)

Namir
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)