Help with Maple (Math Program)

Status
Not open for further replies.

iFargle

Linux / HPC / K8s SME
Staff member
Messages
4,403
Location
N/A
I've decided to learn Maple :thumbsup: My school provides modules to work on in the actual Maple class here, so I found some copies online and am learning it... And am now stuck.

Here's what I have
Code:
[COLOR="red"]>Integral:=proc(f,i)
  local JExact,S,R,E;
    JExact:=int(f,x=0..1);
    S:=rightsum(f,x=0..1,i);
    R:=evalf(%);
    E:=evalf(abs(JExact-R));
 RETURN(
      [Integral]=JExact,
      [Right_Sum]=S,
      [Right_Sum_Eval]=R,
      [Error]=E
 );
end;[/COLOR]

[COLOR="#4169e1"]Integral := proc (f, i) local JExact, S, R, E, pl; JExact := int(f, x = 0 .. 1); S := rightsum(f, x = 0 .. 1, i); R := evalf(%); E := evalf(abs(JExact-R)); rightbox(f, x = 0 .. 1, i); RETURN([Integral] = JExact, [Right_Sum] = S, [Right_Sum_Eval] = R, [Error] = E) end proc[/COLOR]

This outputs to something like this

Code:
>[COLOR="red"]Integral(3*x^2,4);[/COLOR]
[COLOR="#4169e1"][Integral] = 1, [Right_Sum] = (1/4)*(Sum((3/16)*j^2, j = 1 .. 4)), [Right_Sum_Eval] = 1.406250000, [Error] = .406250000[/COLOR]

Okay, that's all fine and dandy. But what I want to do in addition to this is add a plot of the summations for i intervals for the function f. This, normally, can be achieved by using this: rightbox(f,x=0..1,i) over the interval x=0 to x=1 for the function f with i intervals. This will output something that looks like this:

This specific picture graphs the line 3x^2 as well as the Riemann Sum from 0 to 1 using four sub-intervals and the right endpoints of the graph.
rightbox.png

Now my question is.. How would I integrate this rightbox command into my Integral procedure? I've tried just about every combination I can think of, and the help files that came with Maple aren't any help. I'm hoping someone here might know what to do. Thanks for any assistance :thumbsup:

To further clarify, I want it to output the integral of the expression, the Riemann Sum for i sub intervals, and the error associated with the number of sub-intervals and the actual integral over the interval [0,1] as well as the graph generated by the rightbox command.
 
Yep. It's pretty much the same thing as S:=rightsum(f,x=0..1,i), except it outputs it graphically.
 
aha. Never used Maple before but giving myself a quick crash tutorial now :p I'll post up in a bit with some (probably unhelpful and noobish) suggestions lol. Actually (mostly) understand what's going on properly now lol so we'll see.
btw won't this just generate a graph of green which exactly matches the red curve?
How about I just stop talking until I've finished mah eddication.
 
No, the int(f,x=0..1) will. The picture I posted is what i want to see it output. The move intervals you have, the closer it'll get. If you have the program installed, you can see what I mean by doing this:

Code:
> for i from 2 to 20 do
R[i]:=rightsum(x^2,x=0..1,i);
R:=evalf(R[i]);
E:=abs(JExact-R[i]);
rightbox(x^2,x=0..1,i):
pl[i]:=rightbox(x^2,x=0..1,i);
od:

> display([seq(pl[i],i=2..20)],insequence=true);
 
No I don't have it installed, but ok I get what you're getting at now!

Assuming the RETURN part bypasses the fact that proc normally only returns the result from the last command (and thereby returns results from all the local variables), why can't you work rightbox in? (f,i) parameters have already been defined (which is what you'll need for this rightbox command correct?) so just make another variable equal to the result of the rightbox command and pass that variable through in the RETURN statement?
Or is the problem that the rightbox command doesn't accept i as a parameter for defining the number of rectangles?
 
Well it will output something when I have it in there... Here's what I have and what it outputs

Code:
Integral:=proc(f,i)
  local JExact,S,R,E,pl;
    JExact:=int(f,x=0..1);
    S:=rightsum(f,x=0..1,i);
    R:=evalf(%);
    E:=evalf(abs(JExact-R));
    Z:=rightbox(f,x=0..1,i);
 RETURN(
      [Integral]=JExact,
      [Right_Sum]=S,
      [Right_Sum_Eval]=R,
      [Error]=E,
      [Graph]=display(Z)

 );
end;

which outputs:
Code:
Integral(3*x^2,4);
[Integral] = 1, [Right_Sum] = (1/4)*(Sum((3/16)*j^2, j = 1 .. 4)), [Right_Sum_Eval] = 1.406250000, [Error] = .406250000, [Graph] = INTERFACE_PLOT(POLYGONS([[0., 0.], [0., .1875000000], [.2500000000, .1875000000], [.2500000000, 0.]], COLOR(RGB, .7, .9, .7)), POLYGONS([[.2500000000, 0.], [.2500000000, .7500000000], [.5000000000, .7500000000], [.5000000000, 0.]], COLOR(RGB, .7, .9, .7)), POLYGONS([[.5000000000, 0.], [.5000000000, 1.687500000], [.7500000000, 1.687500000], [.7500000000, 0.]], COLOR(RGB, .7, .9, .7)), POLYGONS([[.7500000000, 0.], [.7500000000, 3.], [1., 3.], [1., 0.]], COLOR(RGB, .7, .9, .7)), CURVES([[0., 0.], [0.525760502512563e-2, 0.829272318006788e-4], [0.983221904522613e-2, 0.290017594059922e-3], [0.149768509547739e-1, 0.672918193564533e-3], [0.201555848241206e-1, 0.121874279880696e-2], [0.253097050753769e-1, 0.192174351300768e-2], [0.300882343216080e-1, 0.271590553377598e-2], [0.350361245728643e-1, 0.368259007525580e-2], [0.401532397487437e-1, 0.483684798696028e-2], [0.452539442713568e-1, 0.614375841634520e-2], [0.505006458291457e-1, 0.765094568748244e-2], [0.551219434170854e-1, 0.911528593822910e-2], [0.603244299497488e-1, 0.109171105462864e-1], [0.655482783919598e-1, 0.128897304004496e-1], [0.705824243216081e-1, 0.149456358693466e-1], [0.751539111055276e-1, 0.169443310633726e-1], [0.805898510552764e-1, 0.194841722793349e-1], [0.851948052261307e-1, 0.217744645125550e-1], [0.905514616582915e-1, 0.245987016253591e-1], [0.952930102512563e-1, 0.272422734082381e-1], [.100495240552764, 0.302978801212736e-1], [.105448994020101, 0.333584710195536e-1], [.110617716080402, 0.367088373325333e-1], [.115364216432161, 0.399267072990193e-1], [.120483958291457, 0.435491526167329e-1], [.125801931206030, 0.474783776855002e-1], [.130431242261307, 0.510369268734829e-1], [.135431025025126, 0.550246876180686e-1], [.140596289849246, 0.593019501581198e-1], [.145649493768844, 0.636413251053618e-1], [.150538728391960, 0.679857262376047e-1], [.155967389849246, 0.729774800891603e-1], [.160845283618090, 0.776136157865519e-1], [.166053476381910, 0.827212710555522e-1], [.170772873115578, 0.874901225764478e-1], [.175932420301508, 0.928566495394389e-1], [.180787152110553, 0.980519831047324e-1], [.185861745678392, .103633765519858], [.190823088442211, .109240353247872], [.196017154522613, .115268174601426], [.201019657487437, .121226708089100], [.206135439296482, .127475458001861], [.211208859849246, .133827547436456], [.215870806432161, .139800615209014], [.221213923316583, .146806799607345], [.225992870753769, .153218332894589], [.231088225477387, .160205303862863], [.235965130100503, .167038627870041], [.241380305929648, .174793356272072], [.246069450301508, .181650523115058], [.251391671105528, .189593316903689], [.256242297587940, .196980345219439], [.261548120653266, .205222258251767], [.266126148643216, .212469380975013], [.271339988140704, .220876167492591], [.276376299698492, .229151577105093], [.281409321155779, .237573618100069], [.286423827035176, .246115826080429], [.291241197336683, .254464305078315], [.296448902211055, .263645854866419], [.301412222562814, .272547983730766], [.306635883517588, .282076695181835], [.311364554572864, .290843657533075], [.316590621306533, .300688864497769], [.321596282562814, .310272506874664], [.326589759899498, .319982613813634], [.331805466331658, .330284602462708], [.336609322361809, .339917507702629], [.341529128040201, .349926435899700], [.346961178090452, .361146177305744], [.351879454472362, .371457451439301], [.356909313316583, .382152773796344], [.362024550201005, .393185324844720], [.366726448291457, .403464863629401], [.371738519396985, .414568580410388], [.376712438291457, .425736783490485], [.382032985427136, .437847605863110], [.386728137788945, .448675957673115], [.392145368944724, .461333971154380], [.397034002412060, .472907997214020], [.401871049698492, .484501021757305], [.407072429447236, .497123888448225], [.412294849849246, .509961129636638], [.417046479145729, .521783297303546], [.422092498391960, .534486231596300], [.427016920000000, .547030349898859], [.432355044974874, .560792654745677], [.436974007236181, .572838849000138], [.442279053316583, .586832283007838], [.447266075527638, .600140826953685], [.452204928542714, .613467892194962]............. (and so on and so forth)

It spits out a huge long list of ordered pairs and I don't know how to make these into a graph other than by plotting them outside of the procedure, which would require two lines of code rather than the just the procedure.
 
Could you pass rightsum to rightbox? (duh) I've got an idea, gtg see a friend busk right now but when I get home I'll write it up. Gives me time to think anyway :p
 
Status
Not open for further replies.
Back
Top Bottom