How to call an equation with dependent variables in a function
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
University Glasgow
le 18 Oct 2022
Modifié(e) : Cris LaPierre
le 18 Oct 2022
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 commentaires
Réponse acceptée
Cris LaPierre
le 18 Oct 2022
Modifié(e) : Cris LaPierre
le 18 Oct 2022
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur PDE Solvers dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!