chapter5.page03

# chapter5.page03 - shown in the screen shot that call the...

This preview shows page 1. Sign up to view the full content.

1. NUMERICAL ALGORITHM AND PROGRAMMING IN Mathcad 3 To enter code in Mathcad , (1) First enter the function name with arguments list and assignment operator :=, with sequence of typing, mySolver(f,a,N,tol): (2) Click the Add Line button or press ] to get a vertical bar and two (you should add more by press ] several times). (3) enter x and hold [Shift] type ] to get the local assignment or click on the programming toolbar, at the type a. Notice x a reads as ”assign a to x.” (4) Click for on the programming menu or [Shift][Ctrl][’] to get for in after for enter i , in after , enter ”1;N”, and in under for, press left bracket ] to get a vertical line and several . (5) To get if operator, you need either click on the toolbar or press [Shift][Ctrl][ ] ]. you will get if enter condition in after if and other statements in before if . (6) To get return operator, you need either click on the toolbar or press [Shift][Ctrl][ ], you get return in type any information you want to return. After deﬁning a function, we call it with concrete input data, as
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: shown in the screen shot, that call the mySolver function to ﬁnd zero for both f ( x ) = x 2-1 , with initial guess x = 2 and g ( t ) = t 3-3 t 2-2 t, with initial guess t =-2 . Notice there is two ways to call a function, one way is to deﬁne all arguments before calling the function, another is to deﬁne some arguments and call the function with concrete values for the undeﬁned arguments. As in all programming language, Mathcad allows you to call one function from within another. For example, we could create a function called myDerivative which will compute derivative of a given func-tion f ( x ) at a given number x and step size h > 0 using the forward diﬀerence formula: f ( s ) ≈ f ( x + h )-f ( x ) h . The following screen shot shows the call of myDerivative inside mySolver , Figure 2. Call another function...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online