Programming and Graphics

(Kiana) #1

350 Introduction to C++ Programming and Graphics



  • Matrix definition, addition, and multiplication:


>>a=[12;34]
a=
12
34

>>b=[[12]’[24]’]
b=
12
24

>> a+b
ans =
24
58

>> c = a*b
c=
510
11 22


  • Multiply a complex matrix by a complex vector:


>> a = [1+2i 2+3i; -1-i 1+i]
a=
1.0000 + 2.0000i 2.0000 + 3.0000i
-1.0000 - 1.0000i 1.0000 + 1.0000i

>> v = [1+i 1-i]
v=
1.0000 + 1.0000i 1.0000 - 1.0000i

>> c = a*v’
c=
2.0000 + 6.0000i
-2.0000 + 2.0000i

By taking its transpose indicated by a prime, the row vector,v, becomes a
column vector that is conformable with the square matrix,a.



  • Printπ:


>> format long
>> pi
ans =
3.14159265358979
Free download pdf