永发信息网

matlab连加sum问题求助

答案:2  悬赏:40  手机版
解决时间 2021-03-01 17:06
>> syms x
>> k=1;
>> s=x.^k.*prod(1:2:2.*k-1).^2./(4.^k.*(factorial(k)).^2.*(2.*k-1))

s =

x/4

>> k=2;
>> s=x.^k.*prod(1:2:2.*k-1).^2./(4.^k.*(factorial(k)).^2.*(2.*k-1))

s =

(3*x^2)/64
分别计算时系数为(1/4,3/64)。
连加计算时
>> k=1:2

k =

1 2

>> s=x.^k.*prod(1:2:2.*k-1).^2./(4.^k.*(factorial(k)).^2.*(2.*k-1));
>> sum(s)

ans =

x^2/192 + x/4

>> 系数成(1/4,1/192)了。哪位高手帮忙看一下什么原因,谢谢啦。
最佳答案
clc
clear
syms x
k=1;
s1=x.^k.*prod(1:2:2.*k-1).^2./(4.^k.*(factorial(k)).^2.*(2.*k-1))
p1=prod(1:2:2.*k-1).^2./(4.^k.*(factorial(k)).^2.*(2.*k-1))

k=2;
s2=x.^k.*prod(1:2:2.*k-1).^2./(4.^k.*(factorial(k)).^2.*(2.*k-1))
p2=prod(1:2:2.*k-1).^2./(4.^k.*(factorial(k)).^2.*(2.*k-1))

k=3;
s3=x.^k.*prod(1:2:2.*k-1).^2./(4.^k.*(factorial(k)).^2.*(2.*k-1))
p3=prod(1:2:2.*k-1).^2./(4.^k.*(factorial(k)).^2.*(2.*k-1))

k=4;
s4=x.^k.*prod(1:2:2.*k-1).^2./(4.^k.*(factorial(k)).^2.*(2.*k-1))
p4=prod(1:2:2.*k-1).^2./(4.^k.*(factorial(k)).^2.*(2.*k-1))

for k=1:4
s12=x.^k.*prod(1:2:2.*k-1).^2./(4.^k.*(factorial(k)).^2.*(2.*k-1))
p12=prod(1:2:2.*k-1).^2./(4.^k.*(factorial(k)).^2.*(2.*k-1))
end
用上面语句得出的结果是一致的,但下面的就不同了,
k=1:4
s12=x.^k.*prod(1:2:2.*k-1).^2./(4.^k.*(factorial(k)).^2.*(2.*k-1))
p12=prod(1:2:2.*k-1).^2./(4.^k.*(factorial(k)).^2.*(2.*k-1))
原因在于:当k是标量时,乘方运算与一般的相同,
当k是数组或矩阵时,乘方运算用的是矩阵乘方,所以,结果相差很大
全部回答
matlab中的求和对于常数和一维向量是一样的,对矩阵是对其每一列求和。具体参见函数用法说明 sum sum of elements. s = sum(x) is the sum of the elements of the vector x. if x is a matrix, s is a row vector with the sum over each column. for n-d arrays, sum(x) operates along the first non-singleton dimension. if x is floating point, that is double or single, s is accumulated natively, that is in the same class as x, and s has the same class as x. if x is not floating point, s is accumulated in double and s has class double. s = sum(x,dim) sums along the dimension dim. s = sum(x,'double') and s = sum(x,dim,'double') accumulate s in double and s has class double, even if x is single. s = sum(x,'native') and s = sum(x,dim,'native') accumulate s natively and s has the same class as x. examples: if x = [0 1 2 3 4 5] then sum(x,1) is [3 5 7] and sum(x,2) is [ 3 12]; if x = int8(1:20) then sum(x) accumulates in double and the result is double(210) while sum(x,'native') accumulates in int8, but overflows and saturates to int8(127). see also prod, cumsum, diff, accumarray, isfloat. overloaded methods: codistributed/sum timeseries/sum
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
新蔡到三亚多少公里
何庄地址在哪,我要去那里办事
新东街道社区教育中心我想知道这个在什么地方
中国哪个地方信奉佛教的人多?
请问护坡高是8米、坡面是1:1.5的比例、等于多
衡阳县计生协怎么去啊,有知道地址的么
老婆要给我离婚 而且我们都两个孩子了一个儿
OPPO R7的后置摄像头玻璃碎了,已经全部抠掉
宝儿Time To Begin韩文歌词
冰爽吧地址有知道的么?有点事想过去
为什么感觉身边的人都在对我用心机,都在算计
天天向上tfboys那一期王俊凯是不是把《掌声响
子午庄稼医院在什么地方啊,我要过去处理事情
知乎需要那么追媒体热点呢?
上温东地址在什么地方,想过去办事
推荐资讯
达川机关宾馆在哪里啊,我有事要去这个地方
求一个可以在元旦联欢会上表演的小品或相声之
在剧烈运动时,肌肉处于暂时相对缺氧状态,葡
福建“敢做敢当”的地方是哪?
逃学威龙里面的那个插曲。节奏是噔噔噔噔噔噔
儿童房怎么装温馨
生物膜干涉结果怎么分析
微信小程序开发做好需求分析一共有几步
决定由耳垂的基因叫显性基因(用D表示),三
膝盖受伤后有哪些不伤膝盖的锻炼方法?哪些活
一辆汽车每小时行40千米,自行车每行1千米比汽
如果要买电子产品,你们选择京东还是选择天猫
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?