janhardo

695 Reputation

12 Badges

11 years, 38 days

MaplePrimes Activity


These are replies submitted by janhardo

@acer 

Thanks

Yes, i add a pointplot and extent the array ,but forget to adjust p[0] into p[0,1] 

I took a working procedure from you with maplemint no errors and then with my not working procedure with maple mint with errors and compare.

Its the first time i add quotes ...(could it be that i took old original code from example 2.3 again without quotes, that happened i think)   

That rng::range(numeric definition)  is not precisely explained how it works ..it is in Maple help ?

Evaluation rules the books give explanation about levels and the procedure variables are also different evaluated then in a interactive session.
a=b,b=c,c=d,d=16 is evaluated at   a=16 this is fourth level of evaluation in a interactive session as example.

 

 

@acer 

It was more difficult then i thought to make this procedure Tangentlines(f,a..b), but it is not working as intended.

betounes_ex_set_2_opg_6via_codeexample2.3_uitwerking.mw

@janhardo 

@acer : I leave it to you to add the interval as an additional parameter for your procedures.

You made a procedure out of task (exc set 2 task 3: drawing 6 tangentlines in the inflection points of  f ). 
Now there must be made a procedure from a code example 2.3 (tangentlines at maxs or mins) in book , that was the do task.
But it is now drawing tangentlines for a interval divided in 5 sub intervals with a procedure. 

 

betounes_ex_set_2_opg_6via_codeexample2.3.mw

I am working on it.

maplemint(Tangentlines);
Procedure Tangentlines( f )
  These names were used as global names but were not declared:  black, color,
      thickness, x
  Ineffectual call to with() inside a proc at statement 10: with(plots)

@acer: I suggest that you also add the name x as a local to your procedure, if you intend to continue to utilize it as a dummy name therein. Otherwise your procedure will not work if the name x has been assigned, say, a numeric value at the higher level.

Can you give a example with the procedure ? 
 

 

@janhardo 

Don't know how to make from this factorial function suitable for set and list elements

Factorial:= (n::nonnegint)-> local r:= 1, k:= 0; do r*= ++k until k>=n;

-------------------------------------------------------------------
PR:=proc(A,N)   # PR is product
   p:=1;
   for i from 1 to N do p:=p*A[i] end do:
end proc;

A is a list or set or array

example:

A:=[1,2,3,4];
c:=PR(A,4);
 
To make a factorial 4! from the list A you must fill it with natural numbers : that is not handy

@janhardo 

I am looking now at the factorial definition :

Factorial:= (n::nonnegint)-> local r:= 1, k:= 0; do r*= ++k until k>=n;

or as 2D math input makes a big difference in reading!

for example: n::nonnegint is n element of set Z with 0 and positve numbers elements: 2D is showing the symbol notation 

Is it possible to outcomment 2D math too as with Maple input : # and /*..*/

@Carl Love 

An alternative formulation is

SumList:= (L::list(algebraic))-> 
    if L=[] then 0 else local S:= 0, x; for x in L do S:= S+x od fi
:

This is not looking here above anymore on a procedure definition with proc().. end proc;? 
But it seems to be a procedure. 
Its function made by the operator -> then.

Another point about a while clause of the do statement in relation to summing up a list of numbers 

I can take a partial sum of the list,therefore should be needed a while clause  

@acer 

Thanks

Amazing the root finding. 
After such a long time after 2002 (book),  i  could aspect  that fsolve is surpassed by other rootfinding methods  ?

It's specialized knowledge:numeric rootfinding methods.
I can't  go further  in detail for all sort of functions to use in this procedure, right now that's why my attention goes to other things like maplemint.

 

@Carl Love

Thanks

Get now a good oversight of some loop types

I will study your examples more extensive in Maple   

@acer 

Thanks

Looks great the procedure  when i fill in a function, but by the second one there is a error  message
Error, (in RootFinding:-NextZero) can only handle isolated zeros

It means that there will be limit in what sorts of functions i can enter in the procedure  
example :  sin(x)-x*cos(x)  ..ok and add tan(x) :  sin(x)-x*cos(x)+tan(x)-> error 

I study further with maplemint, because i don't now what rootfinding method to use further ? 

 

 

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] := <Student:-Calculus1:-Roots(ddf(x), x=0..16, numeric)>:
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] := <Student:-Calculus1:-Roots(ddf(x), x=0..16, numeric)>:
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:

Error, `[` unexpected

 

inflectionF(x -> x^sin(x));  

inflectionF(proc (x) options operator, arrow; x^sin(x) end proc)

(1)

 

 

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

Other solution of task .. procedure ?

restart;

with(Student:-Calculus1):
with(plots):

f := x -> x^sin(x);

proc (x) options operator, arrow; x^sin(x) end proc

(2)

df := D(f);

proc (x) options operator, arrow; x^sin(x)*(cos(x)*ln(x)+sin(x)/x) end proc

(3)

ddf := D(D(f));

proc (x) options operator, arrow; x^sin(x)*(cos(x)*ln(x)+sin(x)/x)^2+x^sin(x)*(-sin(x)*ln(x)+2*cos(x)/x-sin(x)/x^2) end proc

(4)

Inflpts := [ fsolve(ddf(x), x=0..16, maxsols=6) ];

[1.395288666, 2.916095859, 7.258616747, 8.576145755, 13.57205647, 14.75675948]

(5)

Q := map(p->[p,f(p)], Inflpts);

[[1.395288666, 1.388167079], [2.916095859, 1.270355627], [7.258616747, 5.161057836], [8.576145755, 5.015577540], [13.57205647, 9.048000408], [14.75675948, 8.947326153]]

(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:

Warning, (in InflectionF) `Q` is implicitly declared local

 

Warning, (in InflectionF) `T` is implicitly declared local

 

inflectionF(x -> x^sin(x));

inflectionF(proc (x) options operator, arrow; x^sin(x) end proc)

(7)

 

 


 

Download betounes_ex_set_2_opg_6.mw

 

@Carl Love 

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 the worksheets from Roger Kraft about programming in Maple 

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

@dharr 

Thanks

Cannot be shorter :)

@Axel Vogt 

Thanks 

Thereis not much to find about this in the book until now  

@Pascal4QM 

Thanks

First 65 66 67 68 69 70 71 Page 67 of 73