matlab怎么写[1 -1 1 -1 .]向量在做这道题:Make the vector lin =[1 2 ⋯ 20] (the integers from 1 to 20),and then makeevery other value in it negative to get lin =[1 −2 3 −4 ⋯ −20]
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/30 20:43:24
![matlab怎么写[1 -1 1 -1 .]向量在做这道题:Make the vector lin =[1 2 ⋯ 20] (the integers from 1 to 20),and then makeevery other value in it negative to get lin =[1 −2 3 −4 ⋯ −20]](/uploads/image/z/6839696-56-6.jpg?t=matlab%E6%80%8E%E4%B9%88%E5%86%99%5B1+-1+1+-1+.%5D%E5%90%91%E9%87%8F%E5%9C%A8%E5%81%9A%E8%BF%99%E9%81%93%E9%A2%98%EF%BC%9AMake+the+vector+lin+%3D%5B1+2+%26%238943%3B+20%5D+%28the+integers+from+1+to+20%29%2Cand+then+makeevery+other+value+in+it+negative+to+get+lin+%3D%5B1+%26%238722%3B2+3+%26%238722%3B4+%26%238943%3B+%26%238722%3B20%5D)
matlab怎么写[1 -1 1 -1 .]向量在做这道题:Make the vector lin =[1 2 ⋯ 20] (the integers from 1 to 20),and then makeevery other value in it negative to get lin =[1 −2 3 −4 ⋯ −20]
matlab怎么写[1 -1 1 -1 .]向量
在做这道题:
Make the vector lin =[1 2 ⋯ 20] (the integers from 1 to 20),and then make
every other value in it negative to get lin =[1 −2 3 −4 ⋯ −20]
matlab怎么写[1 -1 1 -1 .]向量在做这道题:Make the vector lin =[1 2 ⋯ 20] (the integers from 1 to 20),and then makeevery other value in it negative to get lin =[1 −2 3 −4 ⋯ −20]
lin=1:20;
for n=1:length(lin)
lin(n)=lin(n)*(-1).^(n+1)
end
lin
结果为:
Columns 1 through 17
1 -2 3 -4 5 -6 7 -8 9 -10 11 -12 13 -14 15 -16 17
Columns 18 through 20
-18 19 -20