symsum函数错误-无效的索引编制或函数定义? [英] symsum function error - invalid indexing or function definition?

查看:353
本文介绍了symsum函数错误-无效的索引编制或函数定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MATLAB中的symsum函数对以下各项求和:

I'm attempting to sum the following using the symsum function in MATLAB:

总和(从q = 0到5)[a(q + 1)* x(2)^ q]

其中a = [a0,a1,...,a5],x = [x(1),x(2),...]其中x(1),x(2),...是标量.

where a=[a0, a1, ..., a5], x=[x(1), x(2), ...] where x(1), x(2), ... are scalars.

总和为a0 + a1x(2)+ a2x(2)^ 2 + ... + a5x(2)^ 5.

The sum is a0 + a1x(2)+a2x(2)^2 +...+a5x(2)^5.

我使用了以下代码:

syms q a x  
f=a(q+1)*x(2)^q
symsum(f, q, 0, 5)  

其中x(2)= -4.9.

where x(2)= -4.9.

但是,上面的代码返回无效的索引或函数定义".

However, the above code returns "Invalid indexing or function definition".

使用f = x(2)^ q不会导致错误,但是,使用f = a(q + 1)确实会返回错误.因此,问题出在a(q + 1)项之内.

Using f=x(2)^q does not result in the error, however, using f=a(q+1) does return the error. Therefore the problem lies within the a(q+1) term.

任何帮助将不胜感激!

推荐答案

没关系a是符号矩阵还是非符号矩阵.

It doesn't matter a is matrix of symbolics or non-symbolics.

每次调用矩阵都需要一个索引(一个数字,一个实数,例如1,2,3,4,...) 如果q是符号,则表示q确实不等于任何数字,因此a(q) 没有意义,因为q与任何数字均不相等.因此,程序会出错并在执行更多操作之前停止.

Every call to a matrix need an index(a number, real number like 1,2,3,4,...) When q is a symbolic it means q really doesn't equal to any number, so a(q) has no meaning because q has no equality to any number. So programs make error and stops before going more.

>>a=0:5;
>> a(1)

ans =

     0
>>a(q) % ?-->do you know the real value of `q` right now? NO,nobody knows!
    MAKES ERROR

这篇关于symsum函数错误-无效的索引编制或函数定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆