I have: Error using bsxfun Non-singleton dimensions of the two input arrays must match each other.

3 ビュー (過去 30 日間)
So I have some code which I want to get working and I don't understand the error which is being given to me which is: Error using bsxfun
Non-singleton dimensions of the two input arrays must match each other.
My code is:
function A=test_anode(t,D,c_0,Gamma,I_app)
%Compute the mu_n
N=20;
mu_n=zeros(N,1); %array which stores the solutions
old=0;error=10^-8;
for i=1:N
err=10;
while err>error %This solves the iteration x_n+1=atan(x_n)+n*pi
y_n=atan(old)+i*pi;
err=abs(tan(y_n)-y_n);
old=y_n;
end
mu_n(i)=y_n;
end
%Define the functions
a_1=@(s,mu) c_0*(1+mu.^-2).*sin(mu).*exp(-D*mu.^2.*s).*(-cos(mu)*mu.^-1+sin(mu).*mu^-2);
a_2=@(s,mu) -2*Gamma*I_app*(1+mu.^-2).*(sin(mu)).^2.*(1-exp(-D*mu.^2.*s));
%Then populate the matrices
A=bsxfun(a_1,t,mu_n)+bsxfun(a_2,t,mu_n);
The vector t can be anything, not necessarily the same length as mu_n. Is that what is cauing the issue?

回答 (2 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019 年 10 月 17 日
Hi,
Here is the corrected ver. of your code:
function A=test_anode(t,D,c_0,Gamma,I_app)
%Compute the mu_n
N=20;
mu_n=zeros(N,1); %array which stores the solutions
old=0;error=10^-8;
for i=1:N
err=10;
while err>error %This solves the iteration x_n+1=atan(x_n)+n*pi
y_n=atan(old)+i*pi;
err=abs(tan(y_n)-y_n);
old=y_n;
end
mu_n(i)=y_n;
end
%Define the functions
a_1=@(s,mu) c_0*(1+mu.^-2).*sin(mu).*exp(-D*mu.^2.*s).*(-cos(mu).*mu.^-1+sin(mu).*mu.^-2);
a_2=@(s,mu) -2*Gamma*I_app*(1+mu.^-2).*(sin(mu)).^2.*(1-exp(-D*mu.^2.*s));
%Then populate the matrices
A=bsxfun(a_1,t,mu_n)+bsxfun(a_2,t,mu_n);
end
Good luck.
  2 件のコメント
Matthew Hunt
Matthew Hunt 2019 年 10 月 17 日
Thank you for correcting my code but what exactly was wrong with it in the first place?
Matthew Hunt
Matthew Hunt 2019 年 10 月 17 日
Just tested the new version, exactly the same error.

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


Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019 年 10 月 17 日
編集済み: Sulaymon Eshkabilov 2019 年 10 月 17 日
Ok

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by