## 375 Reputation

10 years, 79 days

## betounes ex set 2 task 6...

Try to make a procedure from two code examples what are doing the same.
Start first with only as procedure input a function, but that seems to be not working.
The procedure input must be a function , but the points where the tangentlines must occur inthe procedure is not understood. ( see task6 )

---------------------------------------------------------------------

 >

------------------------------------------------------------------------------------------------

Seems that task 6 is about drawing tangentlines in graph for 6 points (x0..x5) and dividing the interval a..b in 5 intervals
So the procedure input  must be
procedure ( function,interval a..b)
Did not add the interval a..b in the interval in the procedure and  the tw procedures below are not working yet.

================================================================

Example 2.3 code ..

 > restart;
 > with(Student[Calculus1]):
 >
 > f := x -> x^sin(x): df := D(f): ddf := D(D(f)): G := Array(1..6, 1..4): P := Array(1..6, 1..2): G[1..6, 1] := : for i from 1 to 6 do   G[i, 2] := f(G[i, 1]):   G[i, 3] := df(G[i, 1]):   G[i, 4] := G[i,2]+G[i,3]*(x-G[i,1]):   P[i, 1] := plot(G[i,4], x=G[i,1]-1..G[i,1]+1,                   colour=red, adaptive=false, numpoints=2):   P[i, 2] := plots:-pointplot([G[i,1],G[i,2]], symbol=solidcircle,                               symbolsize=15, color=blue): end do: plots:-display(plot(f, 0..16, color=black),                seq(seq(P[i,j], i=1..6), j=1..2),                size=[500,300]);
 >
 >

Using this code for making a procedure.
Function input in procedure : as expression or as function ?

Procedurename : InflectionF (function, interval,two points in interval  )

Note: in code above the interval has a fixed value, so a variable intvx=a..b is needed

 > InflectionF := proc(f)      local df, ddf, G, P, G[1..6, 1], i, j ; df := D(f): ddf := D(D(f)): G := Array(1..6, 1..4): P := Array(1..6, 1..2): G[1..6, 1] := : for i from 1 to 6 do   G[i, 2] := f(G[i, 1]):   G[i, 3] := df(G[i, 1]):   G[i, 4] := G[i,2]+G[i,3]*(x-G[i,1]):   P[i, 1] := plot(G[i,4], x=G[i,1]-1..G[i,1]+1,                   colour=red, adaptive=false, numpoints=2):   P[i, 2] := plots:-pointplot([G[i,1],G[i,2]], symbol=solidcircle,                               symbolsize=15, color=blue): end do: plots:-display(plot(f, 0..16, color=black),                seq(seq(P[i,j], i=1..6), j=1..2),                size=[500,300]); end proc:
 > inflectionF(x -> x^sin(x));
 (1)
 >
 >

-----------------------------------------------------------------------------------------------------------

Other solution of task .. procedure ?

 > restart;
 > with(Student:-Calculus1): with(plots):
 > f := x -> x^sin(x);
 (2)
 > df := D(f);
 (3)
 > ddf := D(D(f));
 (4)
 > Inflpts := [ fsolve(ddf(x), x=0..16, maxsols=6) ];
 (5)
 > Q := map(p->[p,f(p)], Inflpts);
 (6)
 > # The tangent lines, using point-slope form T := seq(plot(df(p)*(x-p)+f(p), x=p-1..p+1), p=Inflpts):
 > display(FunctionPlot(f(x), x=0.0..16.0, sign=[], slope=[],                      caption="", pointoptions=[symbolsize=1],                      concavity=[color(cyan,magenta),filled(coral,wheat)]),         T,         pointplot(Q, symbolsize=10, symbol=solidcircle,                   color=blue, legend="inflection points"),         axis[1]=[tickmarks=Inflpts], size=[800,400]);
 >

-----------------------------------------------------------------------

 > InflectionF := proc(f) local df, ddf, G, P, Inflpts ; df := D(f); ddf := D(D(f)); Inflpts := [ fsolve(ddf(x), x=0..16, maxsols=6) ]; Q := map(p->[p,f(p)], Inflpts); T := seq(plot(df(p)*(x-p)+f(p), x=p-1..p+1), p=Inflpts): display(FunctionPlot(f(x), x=0.0..16.0, sign=[], slope=[],                      caption="", pointoptions=[symbolsize=1],                      concavity=[color(cyan,magenta),filled(coral,wheat)]),         T,         pointplot(Q, symbolsize=10, symbol=solidcircle,                   color=blue, legend="inflection points"),         axis[1]=[tickmarks=Inflpts], size=[800,400]); end proc:
 > inflectionF(x -> x^sin(x));
 (7)
 >

## @Carl Love ThanksIndeed i am strugg...

Thanks

Indeed i am struggling with the loops and try to improve this
Two forms of the do loop
- for-from loop
- for -in loop

Your loopexample in the SumList procedure seems to be advanced ( don't know r+)
Tried making the factorial procedure, but make no progress yet.

Yes, the simpler loop example for the procedure SumList you mentioned, is for now easier to understand
The capital S in the  do loop is a remainder that S is the last executed statement ?

## @acer Thanks I found them back...

Thanks

I found them back the worksheets from Roger Kraft about programming in Maple

https://www.maplesoft.com/applications/view.aspx?SID=4744

## @dharr  Thanks Cannot be shorter ...

Thanks

Cannot be shorter :)

Thanks

Thanks

## @Carl Love ThanksThe use of the unt...

Thanks

The use of the until statement, why to apply in what code context is yet not clear for me

## @Axel Vogt ThanksYes,but is now by ...

Thanks

Yes,but is now by using a procedure for a general case..for all N

## @acer ThanksInteresting books for s...

Thanks

Interesting books for starting for programming and hopefully i can make some progress

It is not my goal to go very deep in the programming skills, because its probably not neccesary and difficult

## @rlopez  Thanks Yes, i did, but d...

Thanks

Yes, i did, but decided to use the book short introduction for now.

## @acer ThanksMakes it not easier to ...

Thanks

Makes it not easier to learn some programming in Maple (only one edition from 2002)

I think there is no other book what teaches a introduction in programming in Maple ?

Can't folllow your explanation what is all wrong with this procedure

Must a variable be declared in a procedure to be local ?, if not they are global ? : assigned outside the scope of the procedure

## @Preben Alsholm ThanksThe book math...

Thanks

The book mathematical computing -An ntroduction to programming using Maple   is way back from 2002 ( don't think there is newer version ? )

When i execute the code nothing happens.

## @acer  Thanks  Makes the gra...

Thanks

Makes the graphs really looking good with the legenda!
(part1 :draw 5 deratives, part 2: draw f, f' and f'' and reasoning  geometric the 3 graphs)

## @acer ThanksI chanced at start at o...

Thanks

I chanced at start at options the Output display to Maple input,that's the culprit

its my own fault..forget that i did this

Well,it is solved now

## exercise set 2 task 4...

 >

 > restart;
 > with(Student:-Calculus1): with(plots):
 > #f := x -> exp(x)^(-x)*sin(x);# wrong
 > f := x -> exp(-x)*sin(x); intvx:= 0..3;
 (1)
 >

to be a one-dimensional array for storing the first five deratives

 > A:=Array(1..5); #functions
 (2)
 > P:=Array(0..5);# plots functions
 >
 >
 (3)

i must make a general expression for f and deratives of f

 >

F1:=D(f); F2:=D(F1);F(3):=D(F2); ....... using the D operator and a do loop for this would be

 > F:=Array(0..5); F[0]:=eval(f); for i from 1 to 5 do F[i]:=D(F[i-1]) end do;
 (4)
 >

step(2) Graph all functions in one plot and use a array for coloring the graphs ?
Try to find out how to do this....

 > # P[i]:=plot(F[i],intvx):
 > # P[0]:=plot(f(x),intvx,color=black);
 > for i from 0 to 5 do   F[i]:   P[i]:=plot(F[i],intvx ): end do:
 > P[0]:=plot(F[0],intvx,color=black):
 > with(plots):
 > display({seq(P[i],i=0..5)}):
 >

Task was using an array to assign colors to each function and scaling plots above ?

 > C:=Array(0..5); #color functions
 > C[0]:=color =red:
 (5)
 > C[1]:=color =blue:
 > C:
 > display({seq(P[i],i=0..1)}):
 > for i from 0 to 5 do   F[i]:   P[i]:=plot(F[i],intvx ): end do:
 >
 > P[0]:=plot(F[0],intvx,C[0],thickness=3):
 > P[1]:=plot(F[1],intvx,C[1],thickness=3):
 >

Ok got a color red in one plot with a C[1] array element

 >
 > C[0]:=color =red; C[1]:=color =blue; C[2]:=color =green; C[3]:= color =black;C[4]:=color =magenta; C[5]:=color =yellow;
 (6)
 >
 > for i from 0 to 5 do
 > P[i]:=plot(F[i],intvx,C[i],thickness=2);  end do:
 >
 >
 > display({seq(P[i],i=0..5)});
 >

Complicated to get a function and his 5 deratives and all colored different by using array's