How to call an equation with dependent variables in a function
1 回表示 (過去 30 日間)
古いコメントを表示
Hi, I'm solving a nonlinear systems of pdes using FDM. I received this error: Index exceeds the number of array elements. Index must not exceed 1. when I tried to run my code. I guess this is because A1, B1, C1 and D1 are taken to be scalars by Matlab but there are not actually scalars but column vectors. A1, B1, C1 and D1 have sizes of theta and v because A1, B1, C1 and D1 functions of thetas'. Please how do I call A1, B1, C1 and D1 in the for loop? Below is just for explanation purposes. I have also attached my full code.
% Simplified parameters
f1 = k1*(cos(theta)).^2 + k3*(sin(theta)).^2;
f2 = (k3-k1).*sin(theta).*cos(theta);
g = (alpha4 + (alpha5-alpha2).*(sin(theta)).^2 -(alpha3+alpha6).*(cos(theta)).^2 + alpha1*(sin(theta)).^2.*(cos(theta)).^2)./2;
m = alpha3.*(cos(theta)).^2 - alpha2*(sin(theta)).^2;
A1 = f1/gamma1;
B1 = f2/gamma1;
C1 = m/gamma1;
D1 = chi_a*H.^2/gamma1;
for i=2:(N-2)
rhsode(i,1) = (A1(i)./(h^2))*(theta(i+1)-2*theta(i)+theta(i-1)) + B1(i).*((theta(i+1)-theta(i-1))./2*h )^2 -(C1(i)/(2*h)).*(v(i+1)-v(i-1)) - D1(i).*sin(theta(i))*cos(theta(i));
end
0 件のコメント
採用された回答
Cris LaPierre
2022 年 10 月 18 日
編集済み: Cris LaPierre
2022 年 10 月 18 日
The error is because D1 is a scalar, not a vector. It also does not appear to be a function of theta. So use D1 instead of D1(i) inside your for loop and that error goes away.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で PDE Solvers についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!