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 中查找有关 Eigenvalue Problems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!