Error using sym/subsindex

132 ビュー (過去 30 日間)
Viktoriia Buliuk
Viktoriia Buliuk 2020 年 8 月 7 日
コメント済み: Viktoriia Buliuk 2020 年 8 月 11 日
Hello!
I got the following mistake:
Error using sym/subsindex (line 836)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function body must be sym
expression.
Error in examp (line 22)
Q(i,j) = (1/(a(i)^(1/2)))* ((t_max - t_min)./(size(t)-1))*symsum(h(k)*wavelet((tau(k)-ttt(j))/a(i)),k, 1, size(h)-1);
The code is following:
type Ez_dry.csv;
Test = importdata('Ez_dry.csv');
t = Test(:, 1);
h = Test(:, 2);
t_max = max(t);
t_min = min(t);
wav = @(tau)(2/(3.^(1/2)*pi^(1/4))*exp(-tau.^2/2).*(1 - tau.^2));
ttt = t_min:0.1*10^-10:t_max;
a = 0.3*10^-10:0.6*10^-11:10^-9;
for i = 1:length(a)
for j = 1:length(ttt)
syms k
Q(i,j) = (1/(a(i)^(1/2)))*((t_max - t_min)./(size(t)-1))*symsum(h(k)*wav((tau(k)-ttt(j))/a(i)),k, 1, size(h)-1);
end
end
S = real(Q);
figure(2);
contour (ttt, 1./a, S, 500)
Could you, please, help me to find a solution. Thank you in advance!
  2 件のコメント
Stijn Haenen
Stijn Haenen 2020 年 8 月 7 日
編集済み: Stijn Haenen 2020 年 8 月 7 日
There is no symbolic variable as input for symsum. You do h(k), but what does this mean, k had not a value yet so you cannot take the k th element of h. And you didn't define tau so tau(k) does not exist. And you should use length(h) instead of size, i think.
If you have a function of h expressed in k you can solve your problem, i dont know if you can without a function for h.
this line works, but h is excluded from it:
sym_sum_ans=(1/(a(i)^(1/2)))*((t_max - t_min)./(size(t)-1))*symsum(wav((k-ttt(j))/a(i)), 1, length(h)-1);
num_ans=vpa(sym_sum_ans)
Viktoriia Buliuk
Viktoriia Buliuk 2020 年 8 月 11 日
Thanks a lot!
I decided to use a loop instead of symsum.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2020 年 8 月 8 日
symbolic variables can never be used as indices. You cannot symsum or symprod and use the control variable as an index.
Instead you need to produce the definite vector of individual values and sum() or prod() that.
  1 件のコメント
Viktoriia Buliuk
Viktoriia Buliuk 2020 年 8 月 11 日
Thank you very much!

サインインしてコメントする。

その他の回答 (1 件)

KSSV
KSSV 2020 年 8 月 7 日
Initialize the cell first.
Q =cell(length(a),length(ttt)) ; % initialize
USe this in the loop.
Q{i,j} = %% your formula with syms
  3 件のコメント
KSSV
KSSV 2020 年 8 月 7 日
Check the spelling.....it should be length
Viktoriia Buliuk
Viktoriia Buliuk 2020 年 8 月 7 日
編集済み: Viktoriia Buliuk 2020 年 8 月 7 日
Thank you!
Unfortunately, I've got the same error:
Error using sym/subsindex (line 836)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function body must be sym expression.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by