janhardo

700 Reputation

12 Badges

11 years, 41 days

MaplePrimes Activity


These are replies submitted by janhardo

@rlopez 

Thanks 

Now i know what's possible. 

@Carl Love 

Thanks

How this statement exactly is build up stays unclear for me.

The piecewise function must for x-values accept : numeric values
Function notation this  must be possible to executed in a plot statement.: plot(h(x) and plot (h) is possible

@Carl Love 

Thanks

Yes, its no problem with the piecewise statement as it works as you mentioned, but the programmingbook likes to program this as exercise
 

@janhardo 

h:= x->`if`( type(x, numeric), 
               piecewise( x<=0,
                          sin(3*x),
                          sin(x/3)
                        ),
              'h(x)'
             ):
Strange maple expression for h  ..thought that i was meant for function definition ( functional oper)ator
Its a if ( condition, function, else...)
Seems that   if   is true then a function in x is created   
 

 

@tomleslie 

Thanks

It was about evaluating rules.

But your programming is a big difference with my example from Maplev5/6 .
To use only expressions in piece-wise functions. 

@acer 

Its not clear how this mechanism works ( R,P)

With this together probably return A[1..n+1,..], P;

(R1,P1):=NewtonM(g,-1,1,1,100,1e-6):

Your note:

note: You don't have to have the procedure return the plot. Given the returned Matrix that was assigned to R4 (for example), you can also get the plot afterwards like this:

Why should i do this ? : i can ask for R4 and P4

@Carl Love 

Thanks

A clear example, but not al my questions are answered.

Another question came up : can i see in a procedure what are the return values? ( automatically)
The last statement in the procedure is the return value, so if there is plot return value, before the last  statement.
Then i must use then add a return statement after the plot statement in order to see the plot in the procedure i think.
 

 

 

 

 

 

@janhardo 

Also this in another procedure: the use of p, L ?

p,L:=approxL( f, a, b, N):
#
# Display function and "piecewsie approximation
# to function
#
  p;
  L;
 

@Carl Love 

Thanks

You can outcomment this and then the procedure get a error.

return A[1..n+1,..], P; in NewtM ac.mw has to do with of (R1,P1):=NewtonM(g,-1,1,1,100,1e-6):?

A is a matrix and P is plot , so this ( ?  ):=procedure ( )  ?  

@janhardo 

The use of return statement is not clear : when to use?

  • return x0;  in exc set task 6 ac .mw 
  • return A[1..n+1,..], P; in NewtM ac.mw

Use of (R1,P1):=NewtonM(g,-1,1,1,100,1e-6): in NewtM ac.mw 

R1; 

P1; 

Seems to split the output of the procedure? 

@mmcdara 

Thanks

This programming of NewtonsMethod is more complicated then programmed on the forum :
showstat(NewtonsMethod);

NewtonsMethod can be used for a idea how its as plot presented to users in the forum programmed version

@acer 

Thanks

That's really programming you did with NewM compared with the book
It shows exactly about the iterations and values and gives insight .

"You wrote "I am leaving most of the rest as it was, and not addressing the inefficiency of augmenting a set with each new plot, or cleaning up the role of A, and so on.

Well that's probably too complicated for me .

Why is there a print command used, while it always with display was? ( was in a earlier code example)

Note: this last NewM is different programmed then the book example   
And there is solve ! (tough)..i tried 3 x times and go then to fsolve

Context sensitive command for solve : selecting the function and Maple shows the solve ( this is possible in the interactive worksheet )..no solution

Ah ,yes of course fsolve ...via contextmenu possible sin(x) - x*cos(x) ?..no
A shortcoming ? 

@acer 

Thanks

Did some more with it


 

 

 

Download exc_set_3_task_6vb_boek.mw

@acer 

Thanks

Looks great and you corrected a lot.
That's is the pittfall when i took over the static code for a procedure  : must analyze better it for the all involving variables.
 The search interval start with a initial value: xinit 

Following the book example for : NewtonM(x->x^2-1,0,2,2,100,1e-4); (parabola )


 

@Carl Love 

Thanks

Maplemint has not detected a variable T a function of x, T:= x->x-f(x)/D(f)(x):

Its corrected, and it was indeed Newton's iteration function as you mentioned.
It was defined at the top of the example worksheet and i did not a solid check for all local variables ( not aware )    

Now i can answer the questions

CDExercises
(1)  Figure 3.9 shows the convergence of Newton's method to a root  r of  the equation sin x - xcos x = 0. This was for
                          "x[0] = 5.5"

 and
                       "epsilon = 0.0001"

, and gives  r =
                         "4.503123428"

, approximately. Obtain a better approximation, as suggested in the book, by using
                           "epsilon"

 = .000001. and altering the above code appropriately. Compare your answer with the approximation to r that you get by using Maple's  fsolve command. How close to zero is  E =| f (r)|  for each of these values of r ?

(2) Alter the above code for Newton's method and use it to draw the picture shown in Figure 3.10 in the book.

The procedure is correct working

exc_set_3_task_6.mw

First 58 59 60 61 62 63 64 Last Page 60 of 73