Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started