Question: Please modify the above code to get the answer to the following question. 2 3 4 5 6 7 8 9 10 11 12 13

Please modify the above code to get the answer to the following question.

2 3 4 5 6 7 8 9 10 11 12 13 14 - 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 clear all; close all; %%%% The basic square domain with uniform separation h between nodes h = 0.005; Nsq = 1/4+1; x = linspace(0,1,Ns); y = linspace(0,1,Ns); x = x'; y = y'; %Create a mapping from the two-D lattice indices to a single Svector index by labelling all the points in the domain (and vice versa) VectoCoord = zeros (0,2); $first index is the vector index and the first %column gives the xindex and the second the yindex for i = 1:Nsg VectoCoord = [VectoCoord;[[1:Nsq]' , i*ones (Nsq,1)]]; end CoordTovec = zeros (Nsq, Nsq); $first element is the xindex and second is the yindex count = 1; $labelling works by giving an index to each node in order. This variable %counts the order out over the nodes. for j = 1:Nsq for i = 1:Nsa CoordToVec(i, j) = count; count = count+1; end end N = Nsq*Nsq; %total number of nodes in whole domain Store Laplacian stencil stencil = %??? in the order: up, down, middle, left, right; This vector contains *the coefficients for each point in the stencil around a middle point %which approximates the Laplacian. You will use them later. 37 - %Find matrix for all nodes A = %??? You can initialize here. You will need to make this a sparse matrix % otherwise the matrix will be too large to compute efficiently from it. b = %??? Initialise the RHS vector here. This will contain the RHS of the %Poisson equation and the boundary conditions for the relevant nodes for i = 1:N %go to each row and put the elements of the matrix in as well as the %boundary conditions xCoord = VectoCoord(i,1); $these are the indexes into the domain on the xaxis yCoord = VectoCoord(i,2); $these are the indexes into the domain on the yaxis xval = x(VectoCoord(i,1)); %what is the value of x yval = y(VectoCoord(i,2)); $what is the value of y if x(xCoord) == 0 || x(xCoord) == 1 || y(y Coord) == 0 || y(yCoord) == 1 $then you are on a boundary node Ali,i) = 1; $implement here a dirichelet condition b(i) = %??? What is the RHS when you are on a boundary 2 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 - 59 60 61 62 63 64 65 66 67 68 - else else you are at an internal node %for the index i in the vector notation, what is the indices for %the up, down, left and right nodes... I will give you one to help upInd = i + Nsq; downInd = %??? leftInd = %??? rightInd = %??? %the elements of the update matrix in row i Ali, upInd) = $772 Ali, downInd) = %??? Ali, i) = %??? Ali,leftInd) = %??? Ali, rightInd) = %??? b(i) = %??? what is the value of the RHS vector? end end sol = %??? What is the solution? Modify the code from Q1 to solve the same Poisson Equation, this time on the rectangular domain 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
