525 views

Uploaded by Ahmat Tahar Abdallah

- Differential Equations With Mathcad Prime
- Programming Tutorial
- Mathcad if Statements
- Mathcad Guide
- MATLAB Workshop Lecture 3
- Lecture 2 - Conditions and Structures
- Comp;
- Getting Started With Python
- Vhdl Syntax
- Prelim Laboratory Exercises_java
- CNC Macros.pdf
- Second Semester 2010-2011 - Schedue of Classes - As of October 26 2010
- PHPUnit Cheat Sheet
- GS Lab Interview Experience
- Report designer Manual - 17.Appendix II
- Php
- Namatreasure Playing programming uv.pdf
- i Year Time Table Session Jan-july-19
- APCSCourseOutline
- QT Ll Assignment Chandpur CASE

You are on page 1of 7

This QuickSheet provides examples of using the conditional if statement in Mathcad programs then compares it with the inline if function. Conditional switches are useful for piecewise definitions, determining loop control, or trapping errors in input arguments. These programs define functions in a piecewise fashion: Note: You must use the if operator −1 otherwise from the Programming gp ( x) := x − floor ( x) if mod ( ceil ( x) , 2) = 1 toolbar in 1 if floor ( x) = x ∧ mod ( ceil ( x) , 2) = 1 programs; do not just type "if." −x + ceil ( x) otherwise fp ( x) := 1 if mod ( ceil ( x) , 2) = 1 These simple programs are equivalent to the command-line if function, although they may be easier to read. fil ( x) := if ( mod ( ceil ( x) , 2) = 1 , 1 , −1) i := 0 .. 100 xi := i ⋅ 0.05

1 0.8 → 0.6 gp ( x) 0.4 0.2 0 0 1 2 3 4 5 6 x 0 1 2 3 4 5 6 x

1 → fp ( x) 0 −1

x := 0 .5 1 x 1.5 2 .01 . 2 4 x x 3 0..This program allows different solutions to an equation for various parameter regimes.85 2 2.50 1 0 0 0. 0.

z return ( a b ) otherwise z←2 c ← root z − y .85 0.9 b ← root z − y .5 This program implements a variable rate structure.5) U1 = ( 0.invrsfct ( y) := if 0 < y < 1 z ← 0.1 a ← root z − y .14 break1 := 240 break2 := 540 .82026299 ) V1 = 1.85 ) V1 = 2.05658830 0.70927557 → U1 V1 U1 = ( 0. z z ← 0. z return c (z ) ) (z (z ) U1 := invrsfct ( 0.12 rate3 := 0.069 rate2 := 0. using external variables to control the conditional expressions: rate1 := 0.85) V1 := invrsfct ( 2.

they all execute.bill ( usage) := if usage < break1 "lowest bracket" return rate1 ⋅ usage Note: the use of strings by themselves if usage < break2 on lines as comments "middle bracket" in the code. if several sequential if statements in a program are true. even if the block ends with an "otherwise. However." For example: x := 4 y←0 y ← y + 3 if x > 3 y ← y + 2 if x > 2 y ← y + 1 otherwise y =5 . return rate2 ⋅ usage otherwise "highest bracket" return rate3 ⋅ usage u := 600 bill ( u) = 84 The otherwise statement above only executes if both if statements are false.

1) = 6. Mathcad returns an error when you try to execute such a program. it returns an error. as a program cannot be unit balanced without knowing the particular value of the inputs.25 These return an error: pow ( 2.5 . have used otherwise statements as well. The expression below can only be executed for dimensionless inputs. 1) = pow ( 2. which have used conditional tests to vary their results. Take the following program: f ( x) := −1 if x < 0 1 if x > 0 In most cases. f ( 0) = . The use of otherwise is important. as it prevents the program from returning unpredictable or incorrect results. the program returns the expected result: f ( 4) = 1 f ( − 2) = − 1 f ( π) = 1 f ( −e) = −1 But if you try to evaluate the function at 0. 3) = 15.Units in Conditional Programs It is not possible to execute a conditional program that returns different units depending on an input value.5 .625 2 3 if n < 2 otherwise Closing Conditional Blocks with Otherwise The previous programs. n) := x x These work: pow ( 2.5 ⋅ m . 3) = pow ( 2. pow ( x .5 ⋅ m .

which balances the equation before calculation to ensure consistent results. the problem arises from with Mathcad's static unit checking. 4cm . adj ) := Vol ← Area ⋅ Length factor ← 2.In this simple case. there is a scenario in which the program might return a result of m6.7 if adj < 2 Vol ⋅ factor prog 2m . Because the definition of factor could fail for certain values of adj (for example.168 m ( 2 ) 3 In this case. which would be m 3. the previous result — in this case. Vol — "falls through" into the definition of factor. The easiest solution is to initially define the return value: f ( x) := res ← 0 res ← −1 if x < 0 res ← 1 if x > 1 f ( 0) = 0 When you create more complex programs. a value of adj is provided that satisfies one of the tests. . however — especially ones involving units — you should close conditional blocks with an otherwise. the problem isn't so obvious. 2 = 0. As a result. Length . Use of the otherwise operator guarantees that one of the steps in the conditional block executes. no definition exists for x = 0. After all. adj = 2. Consider the more complex case: prog ( Area . which doesn't agree with the result if adj = 2. so there doesn't appear to be problem.5). In this case.5 if adj ≥ 3 2.1 if adj = 2 1.

4cm .5 if adj ≥ 3 1. Mathcad flags the last argument in the definition prior to the problematic if block.168 m −2 would return the expected ( 2 ) 3 . Length .7 if adj < 2 2. changing Length from 4cm to 4cm result of m3. Using an otherwise prevents the result prior to the if block from affecting the definition of factor: prog ( Area .To draw attention to this problem.1 otherwise Vol ⋅ factor prog 2m . 2 = 0. and assumes that its units should be changed in order to force the expected result. adj ) := Vol ← Area ⋅ Length factor ← 2.

- Differential Equations With Mathcad PrimeUploaded byM s
- Programming TutorialUploaded byhelover
- Mathcad if StatementsUploaded bysebastian9033
- Mathcad GuideUploaded byBizJet78
- MATLAB Workshop Lecture 3Uploaded byBindesworShrestha
- Lecture 2 - Conditions and StructuresUploaded byRahul Desai
- Comp;Uploaded byAnshuman Dash
- Getting Started With PythonUploaded byLeonardo Sanchez
- Vhdl SyntaxUploaded byAnonymous gP8ivl7f
- Prelim Laboratory Exercises_javaUploaded byJhayar Bucayan
- CNC Macros.pdfUploaded byDn Brtnsch
- Second Semester 2010-2011 - Schedue of Classes - As of October 26 2010Uploaded byNtheng DaVinci
- PHPUnit Cheat SheetUploaded byOxkhar Punt Ocom
- GS Lab Interview ExperienceUploaded byUmang Agrawal
- Report designer Manual - 17.Appendix IIUploaded byeuelvis1045
- PhpUploaded bysupreeth
- Namatreasure Playing programming uv.pdfUploaded byNikos Ioannou
- i Year Time Table Session Jan-july-19Uploaded byyashu
- APCSCourseOutlineUploaded bybunchow
- QT Ll Assignment Chandpur CASEUploaded bySrikanth Vasantada
- PERLUploaded byanil
- Extract Pages From CSEUploaded byellakarunakar
- 2007 Batch ArrearUploaded byVijay Vivegananthan

- 27 HydraulicsAndFloodplainModeling FloodplainDelineation FrenchUploaded byKhaled Hannachi
- TP PISTEUploaded byBen Schiboub
- nomenclUploaded byRubria Rubio Nuñez
- Guide Hecras V3.1.3 Français 2009Uploaded byLucas Antonio
- fancyhdr_fr.pdfUploaded byAhmat Tahar Abdallah
- ABDALLAH TAHAR AHMAT_DEVOIR2_GR1.pdfUploaded byAhmat Tahar Abdallah
- vbexcel.pdfUploaded bySalah Gharbi
- Mathcad Programming - If StatementsUploaded byAhmat Tahar Abdallah
- Creer Sa Propre Extension de FichierUploaded byAhmat Tahar Abdallah
- Formation COVADISUploaded byAhmat Tahar Abdallah

- weblogic Admin ConsoleUploaded byhareesh_jh
- TheraOffice Functional Limitation Reporting Roadmap.pdfUploaded byTony Vlahovic
- abc of pdf using itextUploaded byAnonymous cZTeTlkag9
- measuring samplesUploaded byapi-249283966
- Optimal Portfolio (1)Uploaded bynianiodd
- Basic Water RequirementsUploaded bydimaomar
- Chong Wu Ling-Democratisation and Ethnic MinoritiesUploaded byHariyadi Saja
- Quick-Formatting Hard Disk Drives_ a Shortcut, But SafeUploaded byQais Waqas
- Course Plan SomUploaded byAmitGupta
- Final Year Project Report CSEUploaded byrajat7169451734
- SOLAR SYSTEM Explanation.docUploaded byJade Espiritu
- !!!!teaching critical thinking through literature.pdfUploaded byemysameh
- Eclipse OnlineUploaded bykael895
- Homework 7Uploaded byArthur Ding
- A Study on Progress of Citizen’s Centric E-Governance services in West BengalUploaded byJournal of Computer Applications
- multiscale methodUploaded bySadiq Sarfaraz
- Family Pack QuestionairesUploaded byKeith Howie
- OP_Rations08-22-16Uploaded bylowtech4
- Neural Network vs Regression AnalysisUploaded byAhmadA.Swidan
- sowell conservative.pdfUploaded byFpaulo36
- PILOTING PROCTER & GAMBLE FROM DECISION COCKPITUploaded byKL Manu
- Student IPCC Lab SetupUploaded byApoli Apatoro
- Org ModelsUploaded byAllison Nadine Marchand
- reflection karol b 06052014 pdp frameworkUploaded byapi-254253954
- EMGT101 PinoyBixUploaded byAllen Dela Cruz
- THE LEGAL BASIS OF MATH-1.docxUploaded byhartati
- NecrasovUploaded bySerhiy Voznenko
- 134463221 Motivation LetterUploaded byMahjoub Boujnana
- New Microsoft Word Document.pdfUploaded byAbhishek Abhi
- How to Update Xperia Arc S LT18i and RootingUploaded bylugyan