Attachment 'Functions and Calculus.m'
Download 1 %%
2 x = -3:0.1:3; %(define your x steps)
3 y = x.*x; %(define y)
4 plot(x,y)
5
6 %%
7 x1=linspace(-10,10,1001); %(define your x steps)
8 y1=linspace(-10,10,1001)'; %(define your y steps)
9 [X,Y]=meshgrid(x1,y1); %(combine both into a matrix)
10 z = X.^2+Y.^2;
11 imagesc(x1,y1,z) % (2D plot)
12
13 %%
14 surf(x1,y1,z); shading interp; colorbar % (3D plot)
15
16 %%
17 x1=linspace(-10,10,1001); %(define your x steps)
18 y1=linspace(0,20,1001)'; %(define your y steps)
19 [X,Y]=meshgrid(x1,y1); %(combine both into a matrix)
20
21 wave1D = cos(x1);
22 plot(x1,wave1D);
23
24 %%
25 wave2D1 = cos(X + 2*Y);
26 wave2D2 = cos(0.1*X.^2 + 0.1*Y.^2);
27 figure;
28 imagesc(x1,y1,wave2D1) % (2D plot)
29 figure;
30 imagesc(x1,y1,wave2D2) % (2D plot)
31
32 %%
33 wave1 = cos(0.1*(X-2).^2 + 0.1*Y.^2);
34 wave2 = cos(0.1*(X+2).^2 + 0.1*Y.^2);
35 interference = wave1+wave2;
36 figure
37 imagesc(x1,y1, wave1) % (wave 1)
38 figure
39 imagesc(x1,y1, wave2) % (wave 2)
40 figure
41 imagesc(x1,y1, interference) % (sum of the two)
42
43 %%
44 t = 0:0.1:6; %(define your time steps)
45 y1 = exp(-2*t).*cos(5*t); %(?>k)
46 y2 = exp(-2*t).*cos(0.2*t); %(?<k)
47 figure; hold on;
48 plot(t,y1,'r')
49 plot(t,y2,'k')
50
51 %%
52 x = -3:0.1:3; %(define your x steps)
53 y = x.*x; %(define y)
54 dy = diff(y)/0.1;
55 figure; hold on;
56 plot(x,y,'k');
57 plot(x(1:end-1),dy,'r');
58
59 %%
60 syms x1;
61 y1 = x1.*x1;
62 dy1 = diff(y1);
63 ezplot (dy1, [-3 3]);
64
65 %%
66 syms x;
67 fun= exp(-x).*cos(x);
68 dfun = diff(fun);
69 Q = int(fun,x);
70 %Q = int(fun,x,[1 2]);
71 %double(Q)
72
73 %%
74 syms n; %(Defines x to be a symbol instead of a variable)
75 fun= n;
76 count= 1;
77 for i=0:0.1:3
78 integral(count) = int(fun, n,[0 i]);
79 count = count + 1;
80 end
81 x = 0:0.1:3;
82 y = x;
83 figure; hold on;
84 plot(x,y,'k');
85 plot(x,integral,'r');
86
87 %%
88 Int_y = 0.5*x.*x;
89 plot(x,Int_y,'b');
90
91 %%
92 syms n; %(Defines x to be a symbol instead of a variable)
93 fun= cos(n);
94 count= 1;
95 for i=0:0.1:3
96 integral(count) = int(fun, n,[0 i]);
97 count = count + 1;
98 end
99 x = 0:0.1:3;
100 y = cos(x);
101 figure; hold on;
102 plot(x,y,'k');
103 plot(x,integral,'r');
104
105 %%
106 Int_y = sin(x);
107 plot(x,Int_y,'b');
108 %%
109 syms n; %(Defines x to be a symbol instead of a variable)
110 fun= exp(-n).*cos(n)-n+0.5*n.*n;
111 count= 1;
112 for i=0:0.1:3
113 integral(count) = int(fun, n,[0 i]);
114 count = count + 1;
115 end
116 x = 0:0.1:3;
117 y = exp(-x).*cos(x)-x+0.5*x.*x ;
118 figure; hold on;
119 plot(x,y,'k');
120 plot(x,integral,'r');
121
122 %%
123 syms x;
124 y= tan(x);
125 int(y, x, [-pi/2 pi/2])
126
127 %%
128 x1 = -3.1/2:0.1:3.1/2; %(define x-axis)
129 y1 = tan(x1); %(define your function)
130 plot(x1,y1)
131
132 %%
133 figure
134 hold on
135 ezplot(y,[-pi/2 pi/2]);
136 ezplot(0*x,[-pi/2 pi/2]);
137
138 %%
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.