1 / 16

Алгоритм ба програмчлал

© Б.Алтанхүү , МУИС-ФЭС. Алгоритм ба програмчлал. Mathcad programming. Introduction. A Mathcad program is essentially a multistep function. In Mathcad , a program is made up of a sequence of statements using special operators to control the flow of evaluation.

taite
Télécharger la présentation

Алгоритм ба програмчлал

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ©Б.Алтанхүү, МУИС-ФЭС Алгоритм ба програмчлал Mathcad programming

  2. Introduction • A Mathcad program is essentially a multistep function. • In Mathcad, a program is made up of a sequence of statements using special operators to control the flow of evaluation. • Construct your program, then Mathcad will calculate through the sequence of statements and return the result of the last step as its answer. It can also return a value specified by the "return" statement. • Programs can be used to return every data type that you work with in Mathcad: scalars, arrays, and even text strings. • Mathcad program is created by using its program operators. Mathcad has 10 operators which are accessible from Programming toolbar. You cannot manually type the programming keywords.

  3. "Add Line" • Operator to initiate a program or to add a line to a program. When you click on it, a vertical toolbar and 2 placeholders will be produced. The Add Line declares a program, it also declares multiple line expressions within other program building blocks.

  4. Local assignment operator. • Use the local assignment operator to assign a value to a variable. This is similar to the colon equal sign used in a worksheet; however, a local assignment operator is recognized only inside of the program. All assignments in a program must be made using this local assignment operator.

  5. Conditional operator if • Conditional operator which can be used whenever you want a program statement to be executed only upon the occurrence of some condition.In the right placeholder, enter a Boolean expression.In the left placeholder, enter a statement to evaluate if the Boolean expression is true. If necessary, use the "Add Line" operator to insert placeholders for additional statements.

  6. The otherwise operator • The otherwise operator only works with the if operator; when the condition of the if is not met, Mathcad will execute the accompanying otherwise statement. If you use more than one if statement before an otherwise statement, the otherwise statement is executed only when all previous conditions are false.Enter the otherwise statement in the left placeholder.

  7. For loop • Enter the otherwise statement in the left placeholder. • Use a for loop when you know exactly how many times you want the body of the loop to execute.Type the iterative variable in the placeholder on the left, and the range of values on the right. Place all calculations to be contained in the loop immediately under the "for" so that they are indented. If necessary, use the the "Add Line" operator to insert placeholders for additional statements.

  8. While loop • Use a while loop whenever you want a set of statements to keep executing while a certain condition is true. Make sure you have a statement somewhere that at some point will make the condition false; otherwise, the loop will execute indefinitely and you will need to stop it by pressing [Esc].In the placeholder to the right of the "while," type a Boolean expression.In the placeholder below the "while," enter the statement you want to execute repeatedly. • If necessary, use the "Add Line" to insert placeholders for additional statements.

  9. Return • By default, a program returns the result of the last executed step. However, you can return a specific value from anywhere in the program by using the return operator. The return statement halts program execution and returns a specified value.In the placeholder to the right of the "return," type whatever you would like to return.

  10. Example 1a Example 1b

  11. Example 2

  12. Example 3 Example 4

  13. Example5:for loop • Loop extend shown by indent • ‘Result’ array built up • Note syntax of ‘for’ line • Use when you know in advance how many iterations

  14. Example 6 1 + 3 + 5 + ... + n

  15. Example 7 ... + ... + ere k is an even number: ... + ... + ... + ... + ... + ... +

  16. Төгсөв

More Related