02/23/2016 FREEMAT Tutorial
These are the exercises from the FreeMat packet.
FreeMat v4.2
Copyright (c) 2002-2008 by Samit Basu
Licensed under the GNU Public License (GPL)
Type <help license> to find out more
<helpwin> for online help
<pathtool> to set or change your path
Use <dbauto on/off> to control stop-on-error behavior
Use ctrl-b to stop execution of a function/script
JIT is enabled by default - use jitcontrol to change it
Use <rootpath gui> to set/change where the FreeMat toolbox is installed
--> % Using FREEMAT as a Calculator
--> % Exercise 1
--> 3+4
ans =
7
--> % Exercise 2
--> 6+3/2
ans =
7.5000
--> (6+3)/2
ans =
4.5000
--> 11^2
ans =
121
--> 2*3+4^3
ans =
70
--> % Math Functions
--> % Exercise 1
--> sqrt(67)
ans =
8.1854
--> 2*sin(90)
ans =
1.7880
--> % sin(90) isn't 0 because the argument is in radians
--> 2*sin(6.28)
ans =
-0.0064
--> %Redoing Errors
--> %Exercise 1
--> 3=4
Error: Unexpected input
3=4
^
--> 3+4
ans =
7
--> % Assigning Expressions to Variables
--> % Exercise 1
--> x=2*5
x =
10
--> x
ans =
10
--> x=2*5;
--> x
ans =
10
--> % Creating an Array
--> % Exercise 1
--> C = [1,2,3;4,5,6;7,8,9]
C =
1 2 3
4 5 6
7 8 9
--> % Automatically Creating Vectors
--> % Exercise 1
--> 0:0.5:10
ans =
Columns 1 to 11
0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000 3.5000 4.0000 4.5000 5.0000
Columns 12 to 21
5.5000 6.0000 6.5000 7.0000 7.5000 8.0000 8.5000 9.0000 9.5000 10.0000
--> % Transposing Arrays
--> % Exercise 1
--> test1 = [2 3 4 5]
test1 =
2 3 4 5
--> test2 = test1'
test2 =
2
3
4
5
--> xx = [1 2 3; 4 5 6]
xx =
1 2 3
4 5 6
--> xx'
ans =
1 4
2 5
3 6
--> % Applying Functions to Row Vectors
--> % Exercise 1
--> x = 0:pi/10:2*pi
x =
Columns 1 to 11
0 0.3142 0.6283 0.9425 1.2566 1.5708 1.8850 2.1991 2.5133 2.8274 3.1416
Columns 12 to 21
3.4558 3.7699 4.0841 4.3982 4.7124 5.0265 5.3407 5.6549 5.9690 6.2832
--> y=sin(x)
y =
Columns 1 to 11
0 0.3090 0.5878 0.8090 0.9511 1.0000 0.9511 0.8090 0.5878 0.3090 0.0000
Columns 12 to 21
-0.3090 -0.5878 -0.8090 -0.9511 -1.0000 -0.9511 -0.8090 -0.5878 -0.3090 -0.0000
--> z=cos(x)
z =
Columns 1 to 11
1.0000 0.9511 0.8090 0.5878 0.3090 0.0000 -0.3090 -0.5878 -0.8090 -0.9511 -1.0000
Columns 12 to 21
-0.9511 -0.8090 -0.5878 -0.3090 -0.0000 0.3090 0.5878 0.8090 0.9511 1.0000
--> g=exp(x)
g =
Columns 1 to 11
1.0000 1.3691 1.8745 2.5663 3.5136 4.8105 6.5861 9.0170 12.3453 16.9020 23.1407
Columns 12 to 21
31.6821 43.3762 59.3867 81.3068 111.3178 152.4060 208.6603 285.6784 391.1245 535.4917
--> h=log10(x)
h =
Columns 1 to 11
-Inf -0.5029 -0.2018 -0.0257 0.0992 0.1961 0.2753 0.3422 0.4002 0.4514 0.4971
Columns 12 to 21
0.5385 0.5763 0.6111 0.6433 0.6732 0.7013 0.7276 0.7524 0.7759 0.7982
--> % Array Operations
--> % Exercise 1
--> BB=cos(x)-sin(x)
BB =
Columns 1 to 11
1.0000 0.6420 0.2212 -0.2212 -0.6420 -1.0000 -1.2601 -1.3968 -1.3968 -1.2601 -1.0000
Columns 12 to 21
-0.6420 -0.2212 0.2212 0.6420 1.0000 1.2601 1.3968 1.3968 1.2601 1.0000
--> CC=cos(x)*sin(x)
Error: Requested matrix multiplication requires arguments to be conformant.
--> DD=cos(x).*sin(x)
DD =
Columns 1 to 11
0 0.2939 0.4755 0.4755 0.2939 0.0000 -0.2939 -0.4755 -0.4755 -0.2939 -0.0000
Columns 12 to 21
0.2939 0.4755 0.4755 0.2939 0.0000 -0.2939 -0.4755 -0.4755 -0.2939 -0.0000
--> % Addressing Arrays
--> % Exercise 1
--> m = [1 2 3; 4 5 6; 7 8 9]
m =
1 2 3
4 5 6
7 8 9
--> m(1,:)
ans =
1 2 3
--> m(:,1)
ans =
1
4
7
--> m(1:2,:)
ans =
1 2 3
4 5 6
--> m(:,2:3)
ans =
2 3
5 6
8 9
--> % Creating Simple Plots
--> % Exercise 1
--> degree = 0:2*pi/100:2*pi
degree =
Columns 1 to 11
0 0.0628 0.1257 0.1885 0.2513 0.3142 0.3770 0.4398 0.5027 0.5655 0.6283
Columns 12 to 22
0.6912 0.7540 0.8168 0.8796 0.9425 1.0053 1.0681 1.1310 1.1938 1.2566 1.3195
Columns 23 to 33
1.3823 1.4451 1.5080 1.5708 1.6336 1.6965 1.7593 1.8221 1.8850 1.9478 2.0106
Columns 34 to 44
2.0735 2.1363 2.1991 2.2619 2.3248 2.3876 2.4504 2.5133 2.5761 2.6389 2.7018
Columns 45 to 55
2.7646 2.8274 2.8903 2.9531 3.0159 3.0788 3.1416 3.2044 3.2673 3.3301 3.3929
Columns 56 to 66
3.4558 3.5186 3.5814 3.6442 3.7071 3.7699 3.8327 3.8956 3.9584 4.0212 4.0841
Columns 67 to 77
4.1469 4.2097 4.2726 4.3354 4.3982 4.4611 4.5239 4.5867 4.6496 4.7124 4.7752
Columns 78 to 88
4.8381 4.9009 4.9637 5.0265 5.0894 5.1522 5.2150 5.2779 5.3407 5.4035 5.4664
Columns 89 to 99
5.5292 5.5920 5.6549 5.7177 5.7805 5.8434 5.9062 5.9690 6.0319 6.0947 6.1575
Columns 100 to 101
6.2204 6.2832
--> output=sin(degree);
--> plot(degree,output)
--> hold on
--> plot(degree,cos(degree))
--> a=2
a =
2
--> square
Error: Undefined function or variable square
--> % Solving Simultaneous Equations with MATLAB
--> % Exercise 1
--> R = [50 40; 40 60]
R =
50 40
40 60
--> V = [10; 20]
V =
10
20
--> I = inv(R)*V
I =
-0.1429
0.4286
--> % Operations with Complex Numbers
--> % Exercise 1
--> A=2+2j, B=-1+3j, C=2+j
A =
2.0000 + 2.0000i
B =
-1.0000 + 3.0000i
C =
2.0000 + 1.0000i
--> D=(A*B)/C
D =
-2.4000 + 3.2000i
--> E=(A+B)*C
E =
-3.0000 + 11.0000i
--> % Functions to convert rectangular to polar
--> % Exercise 1
--> A=3+4j,B=3-2j,C=2*exp(50*phase*j)
A =
3.0000 + 4.0000i
B =
3.0000 - 2.0000i
Error: Undefined function or variable phase
-->



0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home