Question: Problem 5 (10 points). Improve the following inefficient code with nested loops by using vectorization method. Hint: you should use meshgrid for this problem. (X,Y,Z]

Problem 5 (10 points). Improve the following inefficient code with nested loops by using vectorization method. Hint: you should use meshgrid for this problem. (X,Y,Z] = meshgrid(xgv, ygv, zgv) produces three-dimensional coordinate arrays. The output coordinate arraysX.Y and Z contain copies of the grid vectors xgv, ygv, and zgv respectively. The sizes of the output arrays are determined by the length of the grid vectors. For grid vectors xgv, ygv, and zgv of length M, N, and P respectively, X,Y, and Z will have N rows, M columns, and P pages. clear all; clc; YOUR ANSWER: clear all; clc; calculating f(x, y, z)=y/ (1+x2)+y"2*sin(z) calculating f(x, y, z)=y/ (1+x^21+y^ 2 * sin (2) by using vectorization method at some discretized points of a 3D volume. at some discrete points of a 3D volume x-linspace (-10,10,100) y-linspace (-10,10,200) z-linspace (-10,10,300) for i=1:length (x) x=linspace (-10, 10, 100) ; y-linspace (-10,10,200) z-linspace (-10,10,300) for j=1:length (y) for k-l:length (z) E(i,j,k)-((1x (i) 2) +y (j) A2*sin (z (k)); end end end
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
