Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have a question regarding matlab I am trying to write a for loop using 3 varia

ID: 3655699 • Letter: I

Question

I have a question regarding matlab I am trying to write a for loop using 3 variables that will calculate the output for each of the variables. The function is a polynomial which is for example 3x + 4y + 5z. I want to find the output for each increase of the variables. So from x goes from 0 - 2 and z goes from 0 - 2 and y goes from 0 - 2. Essentially I should have 8 values as my output which i want to combine into the column of matrix. so every combination from 000 to 222 is an output and put into a column. The code i have is: syms x y z; a=3; b=4; c=5; F= a*x+2*b*y+c*z; G= 3*a*x+ 2*b*y+ 4*c*z; H= 2*a*x+ 3*b*y+4*c*z; for x=0:1:2; y=0:1:2; z=0:1:2; F= a*x+2*b*y+c*z; G= 3*a*x+ 2*b*y+ 4*c*z; H= 2*a*x+ 3*b*y+4*c*z; result11=F(1)+F(2)+F(3); result12=F(4)+F(5)+F(6); result13=F(7)+F(8)+ F(9); result21=G(1)+G(2)+G(3); result22=G(4)+G(5)+G(6); result23=G(7)+G(8)+G(9); result31=H(1)+H(2)+H(3); result32=H(4)+H(5)+H(6); result33=H(7)+H(8)+H(9); A=[result11, result12, result13;result21, result22, result23;result31, result32, result33];

Explanation / Answer

clear all;clc; a=3; b=4;c=5; for x=0:2 for y=0:2 for z=0:2 sum=(a*x)+(b*y)+(c*z); str=sprintf('f(%d,%d,%d)=%d',x,y,z,sum); disp(str); end end end