matlab loop

首页/题库/374℃/2024-07-07 08:49:33

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.

优质解答:

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.

再问: 打进去了 虽然不对 但是我改了下 解决了 可以再帮我做一个吗

再答: 要做什么?这个我没编译,直接在板子上写的…… 错了点,不好意思啊

我来回答修改/报错/举报内容!

猜你喜欢

一个神奇的在线题库网,分享各类考试题库、题目资料与资料答案、在线搜题与练习等!
本网站部分内容、图文来自于网络,如有侵犯您的合法权益,请及时与我们联系,我们将第一时间安排核实及删除!
Copyright © 2021-2024 315题库 All Rights Reserved