SHARE
TWEET

Untitled

a guest Oct 21st, 2019 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function T = myFunction(n,T0,Tend)
  2.     % n is the number of nodes along the rod
  3.     % T0 is the temperature at node zero at x=0
  4.     % Tend is the temperature at the last node at x=L
  5.     % T is a vector of Temperature starting at node zero and going to the last node with Tend.
  6.     % T should have n elements, as the temperature at each node.
  7.     h = 0.01; % [m^-2]
  8.     L = 10; % [m]
  9.     Ta = 20; % C
  10.     % Write your code here:
  11.     onematrix = ones(n-2,1);
  12.     dx = L/(n-1);
  13.     m = h*dx^2;
  14.     A = (2+m)*diag(onematrix)-diag(onematrix(1:end-1),-1)-diag(onematrix(1:end-1),1);
  15.     b = onematrix*m*Ta;
  16.     b(1) = b(1)+T0;
  17.     b(end) = b(end)+Tend;
  18.     T = A\b;
  19.     T = [T0;T;Tend];
  20.     figure()
  21.     plot(T,'r')
  22.     title('reference')
  23.     ylabel('Temperature in [C]')
  24.     xlabel('L in [m]')
  25. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top