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!