Answered step by step
Verified Expert Solution
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 iYou 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 deltaxm and deltaxclcclose all Firstly, let us define our parametersxminA ; m in our casexmaxA ; m in our casexminB xmaxA; m in our casexmaxB ; m in our casedx ; Grid spacing sizenxA intxmaxAxminAdx; Number of cells across Part AnxB intxmaxBxminBdx; Number of cellslA xmaxA xminA; Length of Part AlB xmaxB xminB; Length of Part BTinf ; K in our caseh ; WmKqdot ; Wm in this case kA ; WmK in our casekB ; WmK in our caseitmax ; Let us use to begin withTol ; Let us use E to begin withitcount ; Start the iteration counterTA zerosnxA; Initialise temperature TA array for all points in Part A our initial guess is TAd zerosnxA; Initialise duplicated temperature array for all points in Part ATB zerosnxB; Initialise temperature T array for all points in Part B our initial guess is TBd zerosnxB; Initialise duplicated temperature array for all points in Part Bresitmax zerositmax,; Initialise residual arraytic; This starts our timer for it :itmax Start our loop through iterations for the internal points itcount itcount ; Update iteration counter Firstly, let us take a duplicate of TA and TB This will be the data from our previous iteration. For i this will be our initial guess. Our initial guess is here.TAd TA; Duplicate TA array and store as TAd arrayTBd TB; Duplicate TB array and store as TBd array Part A Boundary pointTATAdqdotdxkA; First cell in T array updated to be TL Part B Boundary TBnxBTBdnxBhdxkBTinfhdxkB; Final cell in T array updated to be TR Part AB Interface nodeTAnxAkAkAkBTAdnxAkBkAkBTBdqdotdxkAkB; Final point in TA array First Point in TB array TB TAnxA; Calculate new internal point values for Part Afor i :nxA TAiTAdi TAdiqdotdxkA;end Calculate new internal point values for Part Bfor i :nxB TBiTBdi TBdi;end Calculate residualresit ; Initialise our residual value for this iteration as Firstly, determine the residual for the boundary nodesresit resit absTATAqdotdxkA;resit resit absTBnxBTBnxBhdxkBTinfhdxkB; Secondly, determine the residual for the interface noderesit resit absTAnxAkkAkBTAnxAkBkAkBTBqdotdxkAkB; Now, determine the residuals for the internal nodes first Part A then Part Bfor i :nxA resit resit absTAiTAi TAiqdotdxkA;endfor i :nxB resit resit absTBiTBi TBi;endif resit Tol fprintfConverged fprintfResidual f resit fprintfNumber of iterations for Convergence d itcountbreakendresitmaxit resit;end End of our iteration loop starting on line toc; 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 behaviourfigureplotresitmax,r'LineWidth', Plots the range of approximate values on the graphhold on Retains plots in the current axes so that new plots addedsetgca'FontSize',; Sets the axis font sizexlim itcount; Sets the x axis limitsxlabelIterations'interpreter','latex','FontSize',; Adds the x labelylabelResidual'interpreter','latex','FontSize',; Adds the y labellegendPointJacobi','interpreter','latex','FontSize', Adds legendgrid onhold offfiguresemilogyresitmax,r'LineWidth',hold on Retains plots in the current axes so that new plots addedsetgca'FontSize',; Sets the axis font sizexlim itcount; Sets the x axis limitsxlabelIterations'interpreter','latex','FontSize',; Adds the x labelylabelResidual'interpreter','latex','FontSize',; Adds the y labellegendPointJacobi','interpreter','latex','FontSize', Adds legendgrid onhold off Now, let us plot our temperature across x plotting both our analytical and numerical answerxA zerosnxA;xA xminA;xAnxA xmaxA;for i :nxA xAi xAi dx; endxB zerosnxB;xB xminB;xBnxB xmaxB;for i :nxB xBi xBi dx; end Analytical resultsxxA xminA::xmaxA; Specify the range of x for our function Steps of are used.xxB xminB::xmaxB; Specify the range of x for our function Steps of are used.TAan @xxAqdotkAxxAqdotlAkAqdotlAlBkB hTinf; This is our analytical function for Part ATBan @xxBqdotlA
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started