janhardo

335 Reputation

8 Badges

11 years, 45 days

MaplePrimes Activity


These are replies submitted by janhardo

 

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 

betounes_ex_set_task_4def.mw


 

 

restart;

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

#f := x -> exp(x)^(-x)*sin(x);# wrong

f := x -> exp(-x)*sin(x); intvx:= 0..3;

proc (x) options operator, arrow; exp(-x)*sin(x) end proc

 

0 .. 3

(1)

 

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

A:=Array(1..5); #functions

Vector[row](5, {(1) = 0, (2) = 0, (3) = 0, (4) = 0, (5) = 0})

(2)

P:=Array(0..5);# plots functions  

 

 

Array(%id = 18446745684388898686)

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

Array(%id = 18446745684388899766)

 

proc (x) options operator, arrow; exp(-x)*sin(x) end proc

 

proc (x) options operator, arrow; -exp(-x)*sin(x)+exp(-x)*cos(x) end proc

 

proc (x) options operator, arrow; -2*exp(-x)*cos(x) end proc

 

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

 

proc (x) options operator, arrow; -4*exp(-x)*sin(x) end proc

 

proc (x) options operator, arrow; 4*exp(-x)*sin(x)-4*exp(-x)*cos(x) end proc

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

Array(%id = 18446745686456624422)

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

color = red

 

color = blue

 

color = green

 

color = black

 

color = magenta

 

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


 

Download betounes_ex_set_task_4def.mw

@janhardo 

exercise set 2-task2

So, the fo  rmula for the [i,j] element is i^j , as i goes from 1 to 3 and j goes from 1 to 4. (Realizing this is likely one of the purposes of the execise.)

A := Array(1..3,1..4):

for i from 1 to 3 do
  for j from 1 to 4 do
    A[i,j] := i^j;
  end do;
end do:

A;

Matrix(3, 4, {(1, 1) = 1, (1, 2) = 1, (1, 3) = 1, (1, 4) = 1, (2, 1) = 2, (2, 2) = 4, (2, 3) = 8, (2, 4) = 16, (3, 1) = 3, (3, 2) = 9, (3, 3) = 27, (3, 4) = 81})

Download doubleloop.mw

But look at these:

Array(1..3,1..4,(i,j)->i^j);

               [1  1  1   1 ]
               [2  4  8   16]
               [3  9  27  81]

A := Array(1..2,1..4):
for i from 1 to 2 do
  for j from 1 to 4 do
    A[i,j] := i^j;
  end do;
end do:
A;

               [1  1  1  1 ]
               [2  4  8  16]

Array(1..2,1..4,(i,j)->i^j);

               [1  1  1  1 ]
               [2  4  8  16]

@acer 

As you wrote :

@janhardo No, it's not a lot more work. Look, the same approach can be done as in the earlier attachment you gave, CD2-5.MWS. The loops are merged together, as I mentioned could be done.

Is there a benefit to make from one array do loop a two nested do loop ?

G := Array(1..6, 1..3):
P := Array(1..6):
for i from 1 to 6 do
  G[i, 1] := L[i];
  G[i, 2] := df(G[i, 1]);
  G[i, 3] := f(G[i,1])+G[i, 2]*(x-G[i,1]);
  P[i] := plot(G[i,3], x=G[i,1]-1..G[i,1]+1, colour=red);
end do:

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

This one does do  the same 

B := Array(1..6,1..3):
for i from 1 to 6 do
  for j from 1 to 3 do
  B[i, 1] := L[i];
  B[i, 2] := df(G[i, 1]);
  B[i, 3] := f(G[i,1])+G[i, 2]*(x-G[i,1]); 
  end do;
end do:

 

@acer 

Thanks!

Now i do see something similar code as in the book, thought first that absence of a regularity in the x-values of f was the problem, but now using a list for random x 

It is better for developing programming skill to use those loops?  
 

"The loops are merged together, as I mentioned could be done."   .... i must look at this ?..ah yes that was the earlier answered task by you  to use a nested do loop for a two-dimensional array

That i think also the intention of the task to use nested do loops , but i can be also be done with a a single loop, if i am i correct.

 

@acer 

Is it not possible to use a 6x2 array for storing the inflection points and y'

The inflection points  for function f are called by: (calculated earlier by you )
Q := map(p->[p,f(p)], Inflpts);

Question :  those  < >  ?

G[1..6, 1] := <Student:-Calculus1:-Roots(ddf(x), x=0..16, numeric)>;

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

Note : The length of the tangentlines must be on a interval  ( see task ) :  

@acer 

Thanks

Interesting you have worked out the task now with array..could try this approach in my task 

It is a lot of work you did opposite the bookexample code  
But in the bookexample it is drawing tangentlines randomly chosen at  x= 0.5,.1.5,2.5,..,5.5 (regularity)  and x=0.5+(i-1) to fill

with a loop the x-values in a array. 

In the task ex set 2-task 3 there are x -values without regularity , so no general formulae to find for using in a do loop 

I learned a lot now.

 

There is a lot to study for this introduction programming...MCtoc.mws

@tomleslie 

Thanks

Now  you drawed the tangentlines in the 6 infliction points of  the graph by a procedure.

Not all is clear for me in the procedure how set this up by you, but that's way i try to learnn programming from the book.

I thought in English language that inflection points also included mins and maxs of a function

That's way i started with a first derative of the function

Next time i give a screenshot of the question of the task , so there will be no room for errors 

@acer 

Thanks

Its all about using in the :  exercise set 2-task 3..  array's and how to come up with them (invent) and to get used of them   
In the book the use is widespread 

Your approach of the task 3 is a different one then is  done in book. 
That is the problem here: i don't have the answers from the author in Maple from the book and try to follow the book    CD2-5.MWS

Note: in enclosed worksheet the tangentlines in maxs or mins of function are not 0 (horizontal) in the  plot :  y' = 0 , strnge that this is not done in the example  -> no it was done for a serie of x-values ( not for x where f '=0 ), so its correct the positions of the tangentline

@acer 

I am following the book where are array used  and not vector or matrix ( it s not vector calculus or matrix calculus what's written in book at the moment ) 

The array is used to store different type of data (types) in Maple : set of points, a equation, a plot  like that.
The next time i upload a worksheet with array questions 

@janhardo 

It is difficult to fill the arrays with the right content ..the reasoning
 

 

 

 

Inflction point : buigpunt

Tangent Lines (Examples 2.1 and 2.3)

   

restart;

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

f:=x->x^sin(x);intvx:= x =0.1..16;

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

 

x = .1 .. 16

(1)

plot(f(x), intvx, gridlines= false);

C:=plot(f(x), intvx, gridlines= false):

 

 

i see 6 inflection points in the graph

df:=D(f);

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

(2)

df_expr:=x^sin(x)*(cos(x)*ln(x)+sin(x)/x);

x^sin(x)*(cos(x)*ln(x)+sin(x)/x)

(3)

Uitzoeken van functievoorschrift naar expressie ivm solve argument-(niet meer nodig ?)

 

 

X:= solve( df_expr =0, x); # standaard solve is niet werkend

0, RootOf(tan(_Z)+ln(_Z)*_Z)

(4)

This is not working this solve for  fprime , so i asked on Mapleprimes forum : needed with(Student:-Calculus1):

Roots(df(x), x=0.1..16, numeric);

[.3522153993, 2.127615825, 4.842558340, 7.914977694, 11.03330637, 14.16379619]

(5)

# Second derivative
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

(6)

 

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

Roots(ddf(x), x=0.1..16, numeric);

[1.395288666, 2.916095860, 7.258616748, 8.576145756, 13.57205647, 14.75675949]

(7)

InflectionPoints(f(x), x=0.1..16, numeric);

[1.395288666, 2.916095860, 7.258616748, 8.576145756, 13.57205647, 14.75675949]

(8)

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

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

(9)

 

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

 

Roots / InflectionPoints / Inflpts  give the same answer.
Now in the spirit of Tangentline example  drawing the tangentlines int he infliction points  

 

The idea is to use two arrays : G and  P for storing inflection points, equation of tangentline and plot tangentline in function f.
The dimension for array G (matrix) is : 6 infliction points = 12 cells  and  6 cells for equation tangentline   
Dimension array G:. 6 points + equation tangentline   ( 6 rows and 3 colums ) : every row can store 3 datatypes.

 

-The inflection points  and the equation of the tangent lines to the graph of f

 are to be stored in a 6 by 3 array called G.

-The plot of f and  the plots of the tangent lines are to be stored in an array P.  First, we declare these arrays.

 

The first row of array G stores the x-value of the first point, the y-value of the first point,  and the equation of the tangent line at the first point.  The second row of G will contain the same information for the second point, the third row the information for the third point, and so on.  The element P[1] of array P will contain the plot of the tangent line at the first point, P[2] will contain the plot of the tangent line at the second point, and so on.  All these assignments can be made easily with the following do loop.

 

 for i from 1 to 6 do
     G[i,1]:= 0.5+(i-1);
     G[i,2]:= f(G[i,1]);
     G[i,3]:= G[i,2]+fprime(G[i,1])*(x-G[i,1]);
     P[i]:=plot(G[i,3],x=G[i,1]-0.8..G[i,1]+0.8,thickness=2):
 od:

You must have asked yourself the question with a given function f  : what do i need for plotting the tangentlines in the inflectionpoints  of graph f ?
Looking at the for statement  ...

 

G:=array(1..6,1..3): # definition of 6 rows and 3 colums array

P:=array(0..6):

The inflection points  for function f are called by:

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]]

(10)

 

To define the equations of the tangent lines we need their slopes.  Thus, we need the derivative function of f.

 

df:=D(f);

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

(11)

 


 

Download betounes_ex_set2_task_3.mw

 

@acer 

Thanks

Its primarily for Maple programming and doing recreational math. 
Basic calculus i know something : function of two variables , double integrals and some more 

But i am a B ed in math focussed on teaching a not a bachelor or master in math who do have stronger math knowledge/skills 

Indeed i gave y' at the start of the thread, because i thought that inflection points also were mins and maxs y-values in the english language for y


 

@janhardo 

For finding real roots there was also another command used: it can be added to the list 

RootFinding:-Analytic(diff(fprime_expr,x,x)=0, re=0..10, im=-1..1);

Thanks

Nice work

Ah i do see the use now of the fsolve command: 

The enclosed example uses array, because they are versatile for programming to use as it seems  

The bookexample draws a tangentline on mins and maxs of y, while this task is for the infliction points of y 

Thanks

Peter Stone i knew already

First 32 33 34 35 36 37 38 Page 34 of 38