matlab loop (a) Define a function handle for the function f(x) = x2.(b) Define the variable S to equal zero.(c) Use a three-line for loop to add each of the following to S in the order given:f(10),f(9),...,f(2),f(1).Don’t display anything.(d) After
来源:学生作业帮助网 编辑:作业帮 时间:2024/06/21 18:50:55
![matlab loop (a) Define a function handle for the function f(x) = x2.(b) Define the variable S to equal zero.(c) Use a three-line for loop to add each of the following to S in the order given:f(10),f(9),...,f(2),f(1).Don’t display anything.(d) After](/uploads/image/z/7250150-38-0.jpg?t=matlab+loop+%28a%29+Define+a+function+handle+for+the+function+f%28x%29+%3D+x2.%28b%29+Define+the+variable+S+to+equal+zero.%28c%29+Use+a+three-line+for+loop+to+add+each+of+the+following+to+S+in+the+order+given%3Af%2810%29%2Cf%289%29%2C...%2Cf%282%29%2Cf%281%29.Don%E2%80%99t+display+anything.%28d%29+After)
matlab loop (a) Define a function handle for the function f(x) = x2.(b) Define the variable S to equal zero.(c) Use a three-line for loop to add each of the following to S in the order given:f(10),f(9),...,f(2),f(1).Don’t display anything.(d) After
matlab loop
(a) Define a function handle for the function f(x) = x2.
(b) Define the variable S to equal zero.
(c) Use a three-line for loop to add each of the following to S in the order given:f(10),
f(9),...,f(2),f(1).Don’t display anything.
(d) After the loop use disp to display the final value of S.
matlab loop (a) Define a function handle for the function f(x) = x2.(b) Define the variable S to equal zero.(c) Use a three-line for loop to add each of the following to S in the order given:f(10),f(9),...,f(2),f(1).Don’t display anything.(d) After
f = @(x)x.^2; %(a) function handler defined
S = 0; %(b) assign the initial value 0 to variable S
for i = 10:-11:1 % (c) initiate the loop that i equals 10, 9, ..., 1
S = f(i); % (c) loop body, calling function handler to retrieve value of S corresponds to each i
end % (c) Thrid line of for loop, close loop
disp(S); %(d) display S with function disp() as required.