Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk/OMNotebook/DrModelica@7435 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
- Loading branch information
Mohsen Torabzadeh-Tari
committed
Dec 16, 2010
1 parent
e42dae2
commit 3c56e88
Showing
1 changed file
with
145 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,161 @@ | ||
<!DOCTYPE OMNotebook> | ||
<Notebook> | ||
<GroupCell closed="false" > | ||
<GroupCell closed="false" > | ||
<TextCell style="Title" > | ||
<Text><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Arial; font-size:38pt; font-weight:600; color:#000000;">Exercise 1</p></body></html></Text> | ||
</TextCell> | ||
<GroupCell closed="false" > | ||
<TextCell style="Section" > | ||
<Text><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times; font-size:18pt; font-weight:600; color:#000000;">Functions</p></body></html></Text> | ||
</TextCell> | ||
<TextCell style="Text" > | ||
<Text><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times New Roman; font-size:12pt; color:#000000;">Write a function <span style=" font-family:Courier New;">faculty</span>, such that faculty(n) = 1*2*3*4*....*n.</p></body></html></Text> | ||
</TextCell> | ||
<InputCell style="Input" closed="true" > | ||
<Input></Input> | ||
<Output></Output> | ||
</InputCell> | ||
<TextCell style="Text" > | ||
<Text><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times New Roman; font-size:12pt; color:#000000;"><br />Call <span style=" font-family:Courier New;">faculty</span> directly.</p></body></html></Text> | ||
</TextCell> | ||
<InputCell style="Input" closed="true" > | ||
<Input></Input> | ||
<Output></Output> | ||
</InputCell> | ||
<TextCell style="Text" > | ||
<Text><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times New Roman; font-size:12pt; color:#000000;"><br />Write a class that contains a function call to <span style=" font-family:Courier New;">faculty</span>.</p></body></html></Text> | ||
</TextCell> | ||
<InputCell style="Input" closed="false" > | ||
<Input></Input> | ||
<Output>114</Output> | ||
</InputCell> | ||
<GroupCell closed="true" > | ||
<TextCell style="Subsection" > | ||
<Text><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times; font-size:14pt; font-weight:600; color:#000000;">Answer</p></body></html></Text> | ||
</TextCell> | ||
<GroupCell closed="false" > | ||
<TextCell style="Subsubsection" > | ||
<Text><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times; font-size:12pt; font-weight:600; color:#000000;">NFaculty</p></body></html></Text> | ||
<GroupCell closed="false"> | ||
<GroupCell closed="false"> | ||
<TextCell style="Title"> | ||
<Text><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> | ||
<html><head><meta name="qrichtext" content="1" /><style type="text/css"> | ||
p, li { white-space: pre-wrap; } | ||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> | ||
<table border="0" style="-qt-table-type: root; margin-top:10px; margin-bottom:10px; margin-left:10px; margin-right:10px;"> | ||
<tr> | ||
<td style="border: none;"> | ||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Arial'; font-size:38pt; font-weight:600; color:#000000;">Exercise 1</span></p></td></tr></table></body></html></Text> | ||
</TextCell> | ||
<InputCell style="Input" closed="false" > | ||
<Input>function NFaculty | ||
<GroupCell closed="false"> | ||
<TextCell style="Section"> | ||
<Text><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> | ||
<html><head><meta name="qrichtext" content="1" /><style type="text/css"> | ||
p, li { white-space: pre-wrap; } | ||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> | ||
<table border="0" style="-qt-table-type: root; margin-top:5px; margin-bottom:5px; margin-left:5px; margin-right:5px;"> | ||
<tr> | ||
<td style="border: none;"> | ||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Times'; font-size:18pt; font-weight:600; color:#000000;">Functions</span></p></td></tr></table></body></html></Text> | ||
</TextCell> | ||
<TextCell style="Text"> | ||
<Text><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> | ||
<html><head><meta name="qrichtext" content="1" /><style type="text/css"> | ||
p, li { white-space: pre-wrap; } | ||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> | ||
<table border="0" style="-qt-table-type: root; margin-top:5px; margin-bottom:5px; margin-left:5px; margin-right:5px;"> | ||
<tr> | ||
<td style="border: none;"> | ||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Times New Roman'; font-size:12pt; color:#000000;">Write a function </span><span style=" font-family:'Courier New'; font-size:12pt; color:#000000;">faculty</span><span style=" font-family:'Times New Roman'; font-size:12pt; color:#000000;">, such that faculty(n) = 1*2*3*4*....*n.</span></p></td></tr></table></body></html></Text> | ||
</TextCell> | ||
<GraphCell AutoX="true" AutoY="true" style="Graph" MinorX="0.1" Antialiasing="false" MinorY="0.1" Title="Plot by OpenModelica" LogX="false" LogY="false" MajorX="1" MajorY="1" closed="true" YLabel="" Area="wEgAAAAAAADAMAAAAAAAAEBZAAAAAAAAQD4AAAAAAAA=" ShowGraph="false" Grid="true" XLabel="" Legend="false"> | ||
<Input></Input> | ||
<Output></Output> | ||
</GraphCell> | ||
<TextCell style="Text"> | ||
<Text><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> | ||
<html><head><meta name="qrichtext" content="1" /><style type="text/css"> | ||
p, li { white-space: pre-wrap; } | ||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> | ||
<table border="0" style="-qt-table-type: root; margin-top:5px; margin-bottom:5px; margin-left:5px; margin-right:5px;"> | ||
<tr> | ||
<td style="border: none;"> | ||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Times New Roman'; font-size:12pt; color:#000000;"><br />Call </span><span style=" font-family:'Courier New'; font-size:12pt; color:#000000;">faculty</span><span style=" font-family:'Times New Roman'; font-size:12pt; color:#000000;"> directly.</span></p></td></tr></table></body></html></Text> | ||
</TextCell> | ||
<GraphCell AutoX="true" AutoY="true" style="Graph" MinorX="0.1" Antialiasing="false" MinorY="0.1" Title="Plot by OpenModelica" LogX="false" LogY="false" MajorX="1" MajorY="1" closed="true" YLabel="" Area="wEgAAAAAAADAMAAAAAAAAEBZAAAAAAAAQD4AAAAAAAA=" ShowGraph="false" Grid="true" XLabel="" Legend="false"> | ||
<Input></Input> | ||
<Output></Output> | ||
</GraphCell> | ||
<TextCell style="Text"> | ||
<Text><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> | ||
<html><head><meta name="qrichtext" content="1" /><style type="text/css"> | ||
p, li { white-space: pre-wrap; } | ||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> | ||
<table border="0" style="-qt-table-type: root; margin-top:5px; margin-bottom:5px; margin-left:5px; margin-right:5px;"> | ||
<tr> | ||
<td style="border: none;"> | ||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Times New Roman'; font-size:12pt; color:#000000;"><br />Write a class that contains a function call to </span><span style=" font-family:'Courier New'; font-size:12pt; color:#000000;">faculty</span><span style=" font-family:'Times New Roman'; font-size:12pt; color:#000000;">.</span></p></td></tr></table></body></html></Text> | ||
</TextCell> | ||
<GraphCell AutoX="true" AutoY="true" style="Graph" MinorX="0.1" Antialiasing="false" MinorY="0.1" Title="Plot by OpenModelica" LogX="false" LogY="false" MajorX="1" MajorY="1" closed="false" YLabel="" Area="wEgAAAAAAADAMAAAAAAAAEBZAAAAAAAAQD4AAAAAAAA=" ShowGraph="false" Grid="true" XLabel="" Legend="false"> | ||
<Input></Input> | ||
<Output>114</Output> | ||
</GraphCell> | ||
<GroupCell closed="false"> | ||
<TextCell style="Subsection"> | ||
<Text><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> | ||
<html><head><meta name="qrichtext" content="1" /><style type="text/css"> | ||
p, li { white-space: pre-wrap; } | ||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> | ||
<table border="0" style="-qt-table-type: root; margin-top:5px; margin-bottom:5px; margin-left:5px; margin-right:5px;"> | ||
<tr> | ||
<td style="border: none;"> | ||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Times'; font-size:14pt; font-weight:600; color:#000000;">Answer</span></p></td></tr></table></body></html></Text> | ||
</TextCell> | ||
<GroupCell closed="false"> | ||
<TextCell style="Subsubsection"> | ||
<Text><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> | ||
<html><head><meta name="qrichtext" content="1" /><style type="text/css"> | ||
p, li { white-space: pre-wrap; } | ||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> | ||
<table style="-qt-table-type: root; margin-top:5px; margin-bottom:5px; margin-left:5px; margin-right:5px;"> | ||
<tr> | ||
<td style="border: none;"> | ||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Times'; font-size:12pt; font-weight:600; color:#000000;">NFaculty</span></p></td></tr></table></body></html></Text> | ||
</TextCell> | ||
<GraphCell AutoX="true" AutoY="true" style="Graph" MinorX="0.1" Antialiasing="false" MinorY="0.1" Title="Plot by OpenModelica" LogX="false" LogY="false" MajorX="1" MajorY="1" closed="false" YLabel="" Area="wEgAAAAAAADAMAAAAAAAAEBZAAAAAAAAQD4AAAAAAAA=" ShowGraph="false" Grid="true" XLabel="" Legend="false"> | ||
<Input>function NFaculty | ||
input Integer n; | ||
output Integer fak = 1; | ||
algorithm | ||
for i in 2:n loop | ||
fak := i*fak; | ||
end for; | ||
end NFaculty;</Input> | ||
<Output>Ok</Output> | ||
</InputCell> | ||
<InputCell style="Input" closed="false" > | ||
<Input>NFaculty(3)</Input> | ||
<Output>114</Output> | ||
</InputCell> | ||
</GroupCell> | ||
<GroupCell closed="false" > | ||
<TextCell style="Subsubsection" > | ||
<Text><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times; font-size:12pt; font-weight:600; color:#000000;">NFacultyCall</p></body></html></Text> | ||
</TextCell> | ||
<InputCell style="Input" closed="true" > | ||
<Input>class NFacultyCall | ||
<Output>Ok</Output> | ||
</GraphCell> | ||
<GraphCell AutoX="true" AutoY="true" style="Graph" MinorX="0.1" Antialiasing="false" MinorY="0.1" Title="Plot by OpenModelica" LogX="false" LogY="false" MajorX="1" MajorY="1" closed="false" YLabel="" Area="wEgAAAAAAADAMAAAAAAAAEBZAAAAAAAAQD4AAAAAAAA=" ShowGraph="false" Grid="true" XLabel="" Legend="false"> | ||
<Input>NFaculty(3)</Input> | ||
<Output>114</Output> | ||
</GraphCell> | ||
</GroupCell> | ||
<GroupCell closed="false"> | ||
<TextCell style="Subsubsection"> | ||
<Text><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> | ||
<html><head><meta name="qrichtext" content="1" /><style type="text/css"> | ||
p, li { white-space: pre-wrap; } | ||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> | ||
<table style="-qt-table-type: root; margin-top:5px; margin-bottom:5px; margin-left:5px; margin-right:5px;"> | ||
<tr> | ||
<td style="border: none;"> | ||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Times'; font-size:12pt; font-weight:600; color:#000000;">NFacultyCall</span></p></td></tr></table></body></html></Text> | ||
</TextCell> | ||
<GraphCell AutoX="true" AutoY="true" style="Graph" MinorX="0.1" Antialiasing="false" MinorY="0.1" Title="Plot by OpenModelica" LogX="false" LogY="false" MajorX="1" MajorY="1" closed="true" YLabel="" Area="wEgAAAAAAADAMAAAAAAAAEBZAAAAAAAAQD4AAAAAAAA=" ShowGraph="false" Grid="true" XLabel="" Legend="false"> | ||
<Input>class NFacultyCall | ||
Real n = NFaculty(4); | ||
end NFacultyCall;</Input> | ||
<Output></Output> | ||
</InputCell> | ||
</GroupCell> | ||
<GroupCell closed="false" > | ||
<TextCell style="Subsubsection" > | ||
<Text><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Times; font-size:12pt; font-weight:600; color:#000000;">Simulation of NFacultyCall</p></body></html></Text> | ||
</TextCell> | ||
<InputCell style="Input" closed="true" > | ||
<Input>simulate( NFacultyCall );</Input> | ||
<Output></Output> | ||
</InputCell> | ||
<TextCell style="Output" > | ||
<Text><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;"><p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Courier New; font-size:11pt; color:#000000;"></p></body></html></Text> | ||
</TextCell> | ||
<InputCell style="Input" closed="true" > | ||
<Input>n[1] | ||
<Output></Output> | ||
</GraphCell> | ||
</GroupCell> | ||
<GroupCell closed="false"> | ||
<TextCell style="Subsubsection"> | ||
<Text><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> | ||
<html><head><meta name="qrichtext" content="1" /><style type="text/css"> | ||
p, li { white-space: pre-wrap; } | ||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> | ||
<table style="-qt-table-type: root; margin-top:5px; margin-bottom:5px; margin-left:5px; margin-right:5px;"> | ||
<tr> | ||
<td style="border: none;"> | ||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Times'; font-size:12pt; font-weight:600; color:#000000;">Simulation of NFacultyCall</span></p></td></tr></table></body></html></Text> | ||
</TextCell> | ||
<GraphCell AutoX="true" AutoY="true" style="Graph" MinorX="0.1" Antialiasing="false" MinorY="0.1" Title="Plot by OpenModelica" LogX="false" LogY="false" MajorX="1" MajorY="1" closed="true" YLabel="" Area="wEgAAAAAAADAMAAAAAAAAEBZAAAAAAAAQD4AAAAAAAA=" ShowGraph="false" Grid="true" XLabel="" Legend="false"> | ||
<Input>simulate( NFacultyCall );</Input> | ||
<Output></Output> | ||
</GraphCell> | ||
<TextCell style="Output"> | ||
<Text><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> | ||
<html><head><meta name="qrichtext" content="1" /><style type="text/css"> | ||
p, li { white-space: pre-wrap; } | ||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> | ||
<table style="-qt-table-type: root; margin-top:5px; margin-bottom:5px; margin-left:5px; margin-right:5px;"> | ||
<tr> | ||
<td style="border: none;"> | ||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p> | ||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Courier New'; font-size:11pt; color:#000000;"></p></td></tr></table></body></html></Text> | ||
</TextCell> | ||
<GraphCell AutoX="true" AutoY="true" style="Graph" MinorX="0.1" Antialiasing="false" MinorY="0.1" Title="Plot by OpenModelica" LogX="false" LogY="false" MajorX="1" MajorY="1" closed="false" YLabel="" Area="wEgAAAAAAADAMAAAAAAAAEBZAAAAAAAAQD4AAAAAAAA=" ShowGraph="false" Grid="true" XLabel="" Legend="false"> | ||
<Input>//n[1] //Doesn't give any output. Erroneous. Replaced by the next line | ||
val (n, 0) | ||
</Input> | ||
<Output></Output> | ||
</InputCell> | ||
</GroupCell> | ||
<Output>24.0</Output> | ||
</GraphCell> | ||
</GroupCell> | ||
</GroupCell> | ||
</GroupCell> | ||
</GroupCell> | ||
</GroupCell> | ||
</GroupCell> | ||
</GroupCell> | ||
</Notebook> |