Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please modify this code to solve the discretised equations developed in ( i ) . You will need to update the parameters involved in the

Please modify this code to solve the discretised equations developed in (i).You will need to update the parameters involved in the calculations based on the provided information. These locations are indicated by "..." in the code.There are also bugs in the code which need to be corrected.(HINT: There are three bugs. One bug is in the Part A boundary point definition. Another bug is in the calculation of the residual for the interface node. The third bug is in the calculation of the analytical temperature distribution for Part B). Provide the results where deltax=0.05m and deltax=0.02clcclose all% Firstly, let us define our parametersxmin_A =...; %...m in our casexmax_A =...; %...m in our casexmin_B = xmax_A; %...m in our casexmax_B =...; %...m in our casedx =...; % Grid spacing sizenx_A = int16((xmax_A-xmin_A)/(dx)); % Number of cells across Part Anx_B = int16((xmax_B-xmin_B)/(dx)); % Number of cellsl_A = xmax_A - xmin_A; % Length of Part Al_B = xmax_B - xmin_B; % Length of Part BT_inf =...; %...K in our caseh =...; %... W.m^-2.K^-1qdot =...; %... W/m^3 in this case k_A =...; %... W.m^-1.K^-1 in our casek_B =...; %... W.m^-1.K^-1 in our caseit_max =...; % Let us use 1000 to begin withTol =0.000001; % Let us use 1E-6 to begin withit_count =0; % Start the iteration counterTA = zeros(1,(nx_A+1))+425; % Initialise temperature T_A array for all points in Part A (our initial guess is 425)TA_d = zeros(1,(nx_A+1))+425; % Initialise duplicated temperature array for all points in Part ATB = zeros(1,(nx_B+1))+425; % Initialise temperature T array for all points in Part B (our initial guess is 425)TB_d = zeros(1,(nx_B+1))+425; % Initialise duplicated temperature array for all points in Part Bres_it_max = zeros(it_max,1); % Initialise residual arraytic; % This starts our timer for it =1:it_max % Start our loop through iterations for the internal points it_count = it_count +1; % Update iteration counter% Firstly, let us take a duplicate of TA and TB. This will be the data from our% previous iteration. For i=1, this will be our initial guess. Our initial% guess is 0 here.TA_d = TA; % Duplicate TA array and store as TA_d arrayTB_d = TB; % Duplicate TB array and store as TB_d array% Part A - Boundary pointTA(1)=(TA_d(2)+((qdot.*dx^2)./(2*k_A)); % First cell in T array updated to be T_L% Part B - Boundary TB(nx_B+1)=(TB_d(nx_B)+(((h*dx)/k_B)*T_inf))/(1+((h*dx)/k_B)); % Final cell in T array updated to be T_R % Part A/B Interface nodeTA(nx_A+1)=(k_A/(k_A+k_B))*TA_d(nx_A)+(k_B/(k_A+k_B))*TB_d(2)+((qdot.*dx^2)./(2*(k_A+k_B))); % Final point in TA array - First Point in TB array TB(1)= TA(nx_A+1);% Calculate new internal point values for Part Afor i =2:nx_A TA(i)=(TA_d(i-1)+ TA_d(i+1)+((qdot.*dx^2)./k_A))/2;end% Calculate new internal point values for Part Bfor i =2:nx_B TB(i)=(TB_d(i-1)+ TB_d(i+1))/2;end% Calculate residualres_it =0.0; % Initialise our residual value for this iteration as 0.% Firstly, determine the residual for the boundary nodesres_it = res_it + abs(TA(1)-((TA(2)+((qdot.*dx^2)./(2*k_A)))));res_it = res_it + abs(TB(nx_B+1)-((TB(nx_B)+(((h*dx)/k_B*T_inf)))/(1+((h*dx)/k_B))));% Secondly, determine the residual for the interface noderes_it = res_it + abs(TA(nx_A+1)-((k/(k_A+k_B))*TA(nx_A)+(k_B/(k_A+k_B))*TB(2)+((qdot.*dx^2)./(2*(k_A+k_B)))));% Now, determine the residuals for the internal nodes - first Part A, then Part Bfor i =2:nx_A res_it = res_it + abs(TA(i)-((TA(i-1)+ TA(i+1)+((qdot.*dx^2)./k_A))/2));endfor i =2:nx_B res_it = res_it + abs(TB(i)-((TB(i-1)+ TB(i+1))/2));endif res_it < Tol fprintf("Converged!") fprintf("Residual =%20.15f", res_it) fprintf("Number of iterations for Convergence =%d", it_count)breakendres_it_max(it)= res_it;end % End of our iteration loop starting on line 43toc; % This gives us our elapsed time to either complete the % maximum number of iterations or obtain a converged solution.% We can now plot our results.% Firstly, let us see our residual behaviourfigure(1)plot(res_it_max,'r','LineWidth',1)% Plots the range of approximate values on the graphhold on % Retains plots in the current axes so that new plots addedset(gca,'FontSize',15); % Sets the axis font sizexlim([0 it_count+1]); % Sets the x axis limitsxlabel('Iterations','interpreter','latex','FontSize',10); % Adds the x labelylabel('Residual','interpreter','latex','FontSize',10); % Adds the y labellegend('Point-Jacobi','interpreter','latex','FontSize',10)% Adds legendgrid onhold offfigure(2)semilogy(res_it_max,'r','LineWidth',1)hold on % Retains plots in the current axes so that new plots addedset(gca,'FontSize',15); % Sets the axis font sizexlim([0 it_count+1]); % Sets the x axis limitsxlabel('Iterations','interpreter','latex','FontSize',10); % Adds the x labelylabel('Residual','interpreter','latex','FontSize',10); % Adds the y labellegend('Point-Jacobi','interpreter','latex','FontSize',10)% Adds legendgrid onhold off% Now, let us plot our temperature across x plotting both our analytical% and numerical answerxA = zeros((nx_A+1),1);xA(1)= xmin_A;xA(nx_A+1)= xmax_A;for i =2:nx_A xA(i)= xA(i-1)+ dx; endxB = zeros((nx_B+1),1);xB(1)= xmin_B;xB(nx_B+1)= xmax_B;for i =2:nx_B xB(i)= xB(i-1)+ dx; end% Analytical resultsxxA = xmin_A:0.001:xmax_A; % Specify the range of x for our function % Steps of 0.001 are used.xxB = xmin_B:0.001:xmax_B; % Specify the range of x for our function % Steps of 0.001 are used.TA_an = @(xxA)-(qdot/(2*k_A)).*xxA.^2+(qdot*(l_A^2)/(2*k_A))+(qdot*l_A*(l_B/k_B +1/h))+T_inf; % This is our analytical function for Part ATB_an = @(xxB)-(qdot*l_A

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 10th International Symposium Sstd 2007 Boston Ma Usa July 2007 Proceedings Lncs 4605

Authors: Dimitris Papadias ,Donghui Zhang ,George Kollios

2007th Edition

3540735399, 978-3540735397

More Books

Students also viewed these Databases questions