在matlab中可以进行符号索引吗? [英] Are symbolic indexing possible in matlab?

查看:220
本文介绍了在matlab中可以进行符号索引吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的函数lnn1c(ii, j, n, n1),它以索引iijj作为参数,其中Kdk1Wdg是一些数组,wg(n)是另一个函数,有点alpha*(n-3)Gdg是一个符号变量.

I have such a function lnn1c(ii, j, n, n1) which takes indexes ii and jj as arguments where Kdk1 and Wdg are some arrays, wg(n) is another function kinda alpha*(n-3) and Gdg is a symbolic variable.

function lnn1c=lnn1c(ii, j, n, n1)
    syms k1Vzdg
    global Gdg Wdg Kdk1
    lnn1c=Gdg-i*(-(Wdg(ii)-Wdg(j))+(wg(n)-wg(n1))+...
        (Kdk1(ii)-Kdk1(j))*k1Vzdg);
end

我想在我的脚本中执行从1到4的索引iij的表达式lnn1c(ii, j, n, n1)的求和. 我尝试了这样的代码

I wanna perform in my script summation of expression lnn1c(ii, j, n, n1) over indexes ii and j from 1 up to 4. I tried such code

syms ii jj n n1
sum(subs(sum(subs(lnn1c(ii, jj, n, n1), ii, 1:4)),jj, 1:4))

但我一直收到这样的错误

but I keep getting such error

索引输入必须是数字,逻辑或':'.

Indexing input must be numeric, logical or ':'.

任何帮助对我来说都是非常宝贵的.

Any help would be really valuable for me.

推荐答案

不,符号索引没有意义.

No, symbolic indexing makes no sense.

但是,您可能会混淆想法.您正在有效地执行subs(f(ii, jj, n, n1), ii, 1:4).您放入ii,然后将其替换为1:4.为什么不将1:4用作输入?

However, you may be mixing ideas. You are effectively doing subs(f(ii, jj, n, n1), ii, 1:4). You put ii and then substitute it by 1:4. Why not put 1:4 as input?

只需:

for jj=1:4
    s=s+sum(lnn1c(1:4, jj, n, n1));
end

当然,您需要nn1 ...的数值. 由于您没有显示完整的代码,因此很难知道您在做什么,但是有暗示说您根本不需要符号数学,而只是在混合编程概念.

Surely you will need numeric values for n and n1.... As you haven't shown the whole code, its hard to know what you are doing, but there are hints to say that you do not need symbolic maths at all and you are just mixing programming concepts.

这篇关于在matlab中可以进行符号索引吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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