Example
In this chapter we are going to define the type complex to represent complex numbers. The following example demonstrates the typical uses that one may wish to make of a mathematical type like complex numbers in a model:
- use of data structures
- various types of initializations and assignments
- products, sums and other arithmetic operations
- comparison
- printed output on screen and to a file.
The following model shows how one might work with a new type complex in Mosel:
model "Test complex" uses "complex" declarations c:complex t:array(1..10) of complex end-declarations forall(j in 1..10) t(j):=complex(j,10-j) t(5):=complex("5+5i") c:=prod(i in 1..5) t(i) if c<>0 then writeln("product: ",c) end-if writeln("sum: ", sum(i in 1..10) t(i)) c:= t(1)*t(3)/t(4) + if(t(2)=0,t(10),t(8)) + t(5) - t(9) writeln("result: ", c) initializations to "test.dat" c t end-initializations end-model