letscheat1234

Matlab Cat 2

Nov 3rd, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 6.24 KB | None | 0 0
  1. MATLAB
  2.  
  3. 1)Bessel fist kind
  4. X = 0:0.1:20;
  5. J = zeros(5,201);
  6. for i=0:4
  7. J(i+1,:) = besselj(i,X);
  8. end
  9. figure('Position',[0 0 1024 768])
  10. plot(X,J,'LineWidth',1.5)
  11. axis([0 20 -.5 1])
  12. grid on;
  13. legend('J_0','J_1','J_2','J_3','J_4','Location','Best')
  14. title('Bessel Functions of the First Kind for n = 0,1,2,3,4')
  15. xlabel('X')
  16. ylabel('J_n(X)')
  17.  
  18. 2)Bessel second kind
  19. X = 0:0.1:20;
  20. Y = zeros(5,201);
  21. for i=0:4
  22. Y(i+1,:) = bessely(i,X);
  23. end
  24. figure('Position',[0 0 1024 768])
  25. plot(X,Y,'LineWidth',1.5)
  26. axis([-0.1 20.2 -2 0.6])
  27. grid on;
  28. legend('Y_0','Y_1','Y_2','Y_3','Y_4','Location','Best')
  29. title('Bessel Functions of the Second Kind for n = 0,1,2,3,4')
  30. xlabel('X')
  31. ylabel('Y_n(X)')
  32.  
  33. 3)Fourier Series
  34.  
  35. clear all
  36. clc
  37. syms x k L U n
  38. f = input('Enter the function: ');
  39. L = input('Enter the lower limit: ');
  40. U = input('Enter the upper limit: ');
  41. l = (U-L)/2;
  42. n = input('Enter the number of terms required: ');
  43. ak = @(f,x,k) int(f*cos(k*pi*x/l)/l,x,L,U);
  44. bk = @(f,x,k) int(f*sin(k*pi*x/l)/l,x,L,U);
  45. fs = @(f,x,n) ak(f,x,0)/2 + ...
  46. symsum(ak(f,x,k)*cos(k*pi*x/l) + bk(f,x,k)*sin(k*pi*x/l),k,1,n);
  47. pretty(fs(f,x,n))
  48. fst = ak(f,x,0)/2;
  49. for i=1:n
  50. fst = fst + ak(f,x,i)*cos(i*pi*x/l) + bk(f,x,i)*sin(i*pi*x/l);
  51. disp(['Harmonics upto:', num2str(i)]);
  52. disp(fst);
  53. h=ezplot(f,[L U]);
  54. set(h,'LineWidth',2)
  55. hold on;
  56. h = ezplot(fst,[L U]);
  57. set(h,'LineStyle','-','Color',[i/n 1/i 1/n],'LineWidth',2);
  58. title(['Partial sums up to n=',num2str(i)])
  59. end
  60.  
  61. 4)Harmonic analysis
  62. clear all
  63. clc
  64. syms t
  65. n = input('Enter the number of data points n : ');
  66. x_0 = input('Enter the starting value of x : ');
  67. s = input('Enter the length of the spacing between successive values of x :
  68. ');
  69. count = input('Enter 0 if the unit of x is degrees, otherwise enter a nonzero
  70. number: ');
  71. y = input('Enter the y values (as a row vector): ');
  72. n1 = input('Enter the number of harmonic of the series n1 : ');
  73. x = x_0 + (0:n-1)*s;
  74. if(count == 0)
  75. x=x*pi/180;
  76. s=s*pi/180;
  77. end
  78. l=0.5*(x(n)+s-x(1)); % l=pi if it is degree
  79. a_0 = (2/n)*sum(y);
  80. for i=1:n1
  81. yc=y.*cos(i*pi*x/l);
  82. ys=y.*sin(i*pi*x/l);
  83. a(i)=(2/n)*sum(yc);
  84. b(i)=(2/n)*sum(ys);
  85. end
  86. F_s=a_0/2;
  87. figure('Position',[1 1 1024 768])
  88. for i=1:n1
  89. subplot(n1,1,i)
  90. plot(x,y,'r*');
  91. hold on
  92. F_s = F_s+a(i).*cos(i*pi*t/l)+b(i).*sin(i*pi*t/l);
  93. ezplot(F_s, [x(1) x(n)])
  94. title(['Harmonics up to: ', num2str(i)])
  95. end
  96. disp('Fourier series : ')
  97. vpa(F_s,4)
  98.  
  99. 5)second order difference equation with constant coeff
  100. clear all
  101. clc
  102. syms n k1 k2
  103. a = input('Enter the coefficient of y(n+2): ');
  104. b = input('Enter the coefficient of y(n+1): ');
  105. c = input('Enter the coefficient of y(n): ');
  106. g = input('Enter the non-homogeneous part: ');
  107. r = roots([a b c]);
  108. if imag(r)~=0
  109. rho = sqrt(real(r(1))^2 + imag(r(1))^2);
  110. theta = atan(abs(imag(r(1)))/real(r(1)));
  111. y1 = (rho^n)*cos(n*theta);
  112. y2 = (rho^n)*sin(n*theta);
  113. elseif r(1)==r(2)
  114. y1 = r(1)^n;
  115. y2 = n*r(1)^n;
  116. else
  117. y1 = r(1)^n;
  118. y2 = r(2)^n;
  119. end
  120. Co = det([y1, y2;subs(y1,n,n+1), subs(y2,n,n+1)]); %Casoratian of the solutions
  121. y_c = k1*y1 + k2*y2;
  122. disp('Complementary Solution is: ');
  123. disp(y_c);
  124. if(g ~= 0)
  125. y11 = subs(y1,n,n+1);
  126. y21 = subs(y2,n,n+1);
  127. 36
  128. Co1 = subs(Co,n,n+1);
  129. u1 = simplify(symsum(-g*y21/Co1,n,0,n-1));
  130. u2 = simplify(symsum(g*y11/Co1,n,0,n-1));
  131. y_p = simplify(u1*y1+u2*y2);
  132. y = y_c + y_p;
  133. else
  134. y = y_c;
  135. end
  136. check = input('If the given problem has initial conditions then enter 1 else enter 0: ');
  137. if (check == 1)
  138. yval1 = input('Enter the initial condition at n = 0: ');
  139. yval2 = input('Enter the initial condition at n = 1: ');
  140. cond1 = strcat(char(subs(y,n,0)),'=',num2str(yval1));
  141. cond2 = strcat(char(subs(y,n,1)),'=',num2str(yval2));
  142. [k1,k2] = solve(cond1,cond2);
  143. y = subs(y);
  144. end
  145. disp('Complete Solution is: ')
  146. disp(collect(collect(y,y1),y2))
  147. if(check ~= 0)
  148. nrange = linspace(0,10,40);
  149. Y = subs(y,n,nrange);
  150. stem(nrange,Y);
  151. set(gca,'XTick',linspace(0,10,11))
  152. xlabel('n');
  153. ylabel('y(n)');
  154. end
  155.  
  156. 6)SOLUTION OF FIRST AND SECOND ORDER DIFFERENCE EQUATIONS USING Z – TRANSFORM
  157.  
  158. clc
  159. clear all
  160. syms n z Yz g
  161. yn = sym('y(n)');
  162. yn1 = sym('y(n+1)');
  163. yn2 = sym('y(n+2)');
  164. a = input('The Coefficient of y(n+2) = ');
  165. b = input('The Coefficient of y(n+1) = ');
  166. c = input('The Coefficient of y(n) = ');
  167. nh = input('The Non Homogeneous part ');
  168. eq = a*yn2 + b*yn1 + c*yn - nh;
  169. Zeq = ztrans(eq, n, z);
  170. if (a==0)
  171. d = input('The initial value at 0 is ');
  172. Zeq = subs(Zeq,{'ztrans(y(n), n, z)', 'y(0)'}, {Yz, d});
  173. else
  174. d = input('The initial value at 0 is ');
  175. e = input('The initial value at 1 is ');
  176. Zeq = subs(Zeq,{'ztrans(y(n), n, z)', 'y(0)', 'y(1)'}, {Yz, d, e});
  177. end
  178. eq = collect(Zeq, Yz);
  179. Y = solve(eq, Yz);
  180. Y = iztrans(Y, z, n);
  181. Y = simple(Y)
  182. m = 0:20;
  183. y = double(subs(Y,n,m));
  184. stem(y)
  185. title('Difference equation');
  186. xlabel('n'); ylabel('y(n)');
  187.  
  188.  
  189. forms
  190.  
  191. <html>
  192. <body>
  193. <table>
  194. <tr>
  195. <td>Name:</td>
  196. <td><input type="text" name="name" value="" size="25"></td>
  197. </tr>
  198.  
  199. <tr>
  200. <td>Address:</td>
  201. <td><input type="text" name="address" value="" size="25"></td>
  202. </tr>
  203.  
  204. <tr>
  205. <td>City:</td>
  206. <td><input type="text" name="city" value="" size="25"></td>
  207. </tr>
  208.  
  209. <tr>
  210. <td>State:</td>
  211. <td><input type="text" name="state" value="" size="25"></td>
  212. </tr>
  213.  
  214. <tr>
  215. <td>Zip:</td>
  216. <td><input type="text" name="zip" value="" size="25"></td>
  217. </tr>
  218.  
  219. <tr>
  220. <td>Magazine:</td>
  221. <td><select name = "newspaper">
  222. <option value="1" selected = "selected">The Times Of India</option>
  223. <option value="2" selected = "selected">Hindustan Times</option>
  224. </select>
  225. </td>
  226. </tr>
  227.  
  228. <tr>
  229. <td>Subscription:</td>
  230. <td><input type ="radio" name="1yr" value="1" checked ="checked">1 year
  231. <input type ="radio" name="1yr" value="1" >2 year</td>
  232. </tr>
  233. </table>
  234. </br>
  235.  
  236. Additional Comments: </br>
  237.  <textarea name="add com" rows="10" cols="30">
  238. </textarea>
  239. </br>
  240. <input type="submit" name="submitbtn" value ="submit"/>
  241.  
  242.  
  243. </body>
  244. </html>
  245.  
  246.  
  247. frames
  248.  
  249. <!DOCTYPE html>
  250. <html>
  251. <title>Frames</title>
  252. <frameset rows="20%,80%">
  253.     <frame name="top" src="/html/top_frame.htm"/>
  254.     <frameset cols="20%,80%">
  255.     <frame name="left" src="file:///tmp/guest-JFl73a/Desktop/a.html"/>
  256.     <frame name="right" />
  257.     </frameset>
  258. </frameset>
  259. </html>
  260.  
  261.  
  262. link to frame
  263.  
  264. <!DOCTYPE html>
  265. <html>
  266. <title>group</title>
  267. <body>
  268. <a href="http://www.tutorialspoint.com" target="right">click here!</a>
  269. </body>
  270. </html>
Advertisement
Add Comment
Please, Sign In to add comment