the array index is not matching

1 回表示 (過去 30 日間)
yogeshwari patel
yogeshwari patel 2024 年 11 月 28 日
コメント済み: yogeshwari patel 2024 年 12 月 2 日
syms x mu gamma
syms t %c
alpha=1
U=zeros(1,2,'sym')
V=zeros(1,2,'sym');
A=zeros(1,1,'sym');
B=zeros(1,1,'sym');
C=zeros(1,1,'sym');
D=zeros(1,1,'sym');
series1(x,t)=sym(zeros(1,1));
series2(x,t)=sym(zeros(1,1));
%%%%%%%%%%%%%%%%%%%%% initial condition
%mu=1
U(1)=mu*exp(1i*x)
V(1)=gamma*exp(1i*x)
u=conj(U(1))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for m=1
A(1)=0;
B(1)=0;
for j=1:m
for k=1:j
A(1)=A(1)+U(k)*V(j-k+1)*conj(V(m-j+1));
B(1)=B(1)+V(k)*U(j-k+1)*conj(U(m-j+1));
end
end
U(m+1)=gamma(((m-1)*alpha)+1)/gamma((alpha*(m+1-1))+1)*1i*(1i*diff(U(m),x,1)+V(m)+A(1))
V(m+1)=gamma(((m-1)*alpha)+1)/gamma((alpha*(m+1-1))+1)*(-1i*diff(V(m),x,1)+U(m)+B(1))
end
Index exceeds the number of array elements. Index must not exceed 1.
Error in indexing (line 936)
R_tilde = builtin('subsref',L_tilde,Idx);
why it showing the error ? As I will compute diff(U(m),x,1)+V(m)+A(1)) . The index in each term will be 1 .
  1 件のコメント
yogeshwari patel
yogeshwari patel 2024 年 12 月 2 日
Thanks

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

採用された回答

Vinay
Vinay 2024 年 11 月 28 日
The issue is due to the 'gamma' variable which is being used both as a symbolic variable and as a function in the below code
U(m+1)=gamma(((m-1)*alpha)+1)/gamma((alpha*(m+1-1))+1)*1i*(1i*diff(U(m),x,1)+V(m)+A(1))
V(m+1)=gamma(((m-1)*alpha)+1)/gamma((alpha*(m+1-1))+1)*(-1i*diff(V(m),x,1)+U(m)+B(1))
The above code treats 'gamma' as a function and causing the error.The workaround is to use the multiplication operator after the variable 'gamma' in the expression
U(m+1)=gamma*(((m-1)*alpha)+1)/gamma*((alpha*(m+1-1))+1)*1i*(1i*diff(U(m),x,1)+V(m)+A(1))
V(m+1)=gamma*(((m-1)*alpha)+1)/gamma*((alpha*(m+1-1))+1)*(-1i*diff(V(m),x,1)+U(m)+B(1))
I hope this helps!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by