Problem with matrix dimensions
Hello, my code is giving me the error :
Error using
Matrix dimensions must agree.
I don’t know why because the matrices I am trying to divide have the dimensions of 5×1 and 5×5
function F = sistema(X)
beta1 = 0.0000009;
beta2 = 0.00000093;
M = 1;
p = 0.1;
mu = 0.00001;
rho = 0.00002;
theta = 0.005;
omega = 0.05;
gamma = 0.001;
alpha1 = 0.0001;
alpha2 = 0.004;
S = X(1);
E = X(2);
I = X(3);
Q = X(4);
V = X(5);
F(1) = p*M – beta1*S*E – beta2*S*I – (rho + mu)*S;
F(2) = beta1*S*E + beta2*S*I – (omega + alpha1 + mu)*E;
F(3) = omega*E – (gamma + alpha2 + mu)*I;
F(4) = alpha1*E + alpha2*I – (theta + mu)*Q;
F(5) = (1 – p)*M + rho*S + gamma*I + theta*Q – mu*V;
end
function JF = jacobiano(X)
beta1 = 0.0000009;
beta2 = 0.00000093;
M = 1;
p = 0.1;
mu = 0.00001;
rho = 0.00002;
theta = 0.005;
omega = 0.05;
gamma = 0.001;
alpha1 = 0.0001;
alpha2 = 0.004;
S = X(1);
E = X(2);
I = X(3);
Q = X(4);
V = X(5);
JF = [-beta1*E – beta2*I – rho – mu, -beta1*S, -beta2*S, 0, 0;
beta1*E, beta1*S – (omega + alpha1 + mu), beta2*S, 0, 0;
0, omega, -(gamma + alpha2 + mu), 0, 0;
0, alpha1, alpha2, -(theta + mu), 0;
rho, 0, gamma, theta, -mu];
end
These are the codes of the two functions that qive the matrices
function [x, it, norma_diferenca] = metodo_newton2(F, JF, y0, e, nmax)
x = y0;
it = 0;
norma_diferenca = Inf;
while norma_diferenca > e && it < nmax
Fx = F(x);
JFx = JF(x);
div = JFx (-Fx);
x = x + div;
norma_diferenca = norm(div);
it = it + 1;
end
if it >= nmax
disp(‘Atingido o número máximo de iterações sem convergência.’);
end
end
And this is the code taht divide the two matrices.Hello, my code is giving me the error :
Error using
Matrix dimensions must agree.
I don’t know why because the matrices I am trying to divide have the dimensions of 5×1 and 5×5
function F = sistema(X)
beta1 = 0.0000009;
beta2 = 0.00000093;
M = 1;
p = 0.1;
mu = 0.00001;
rho = 0.00002;
theta = 0.005;
omega = 0.05;
gamma = 0.001;
alpha1 = 0.0001;
alpha2 = 0.004;
S = X(1);
E = X(2);
I = X(3);
Q = X(4);
V = X(5);
F(1) = p*M – beta1*S*E – beta2*S*I – (rho + mu)*S;
F(2) = beta1*S*E + beta2*S*I – (omega + alpha1 + mu)*E;
F(3) = omega*E – (gamma + alpha2 + mu)*I;
F(4) = alpha1*E + alpha2*I – (theta + mu)*Q;
F(5) = (1 – p)*M + rho*S + gamma*I + theta*Q – mu*V;
end
function JF = jacobiano(X)
beta1 = 0.0000009;
beta2 = 0.00000093;
M = 1;
p = 0.1;
mu = 0.00001;
rho = 0.00002;
theta = 0.005;
omega = 0.05;
gamma = 0.001;
alpha1 = 0.0001;
alpha2 = 0.004;
S = X(1);
E = X(2);
I = X(3);
Q = X(4);
V = X(5);
JF = [-beta1*E – beta2*I – rho – mu, -beta1*S, -beta2*S, 0, 0;
beta1*E, beta1*S – (omega + alpha1 + mu), beta2*S, 0, 0;
0, omega, -(gamma + alpha2 + mu), 0, 0;
0, alpha1, alpha2, -(theta + mu), 0;
rho, 0, gamma, theta, -mu];
end
These are the codes of the two functions that qive the matrices
function [x, it, norma_diferenca] = metodo_newton2(F, JF, y0, e, nmax)
x = y0;
it = 0;
norma_diferenca = Inf;
while norma_diferenca > e && it < nmax
Fx = F(x);
JFx = JF(x);
div = JFx (-Fx);
x = x + div;
norma_diferenca = norm(div);
it = it + 1;
end
if it >= nmax
disp(‘Atingido o número máximo de iterações sem convergência.’);
end
end
And this is the code taht divide the two matrices. Hello, my code is giving me the error :
Error using
Matrix dimensions must agree.
I don’t know why because the matrices I am trying to divide have the dimensions of 5×1 and 5×5
function F = sistema(X)
beta1 = 0.0000009;
beta2 = 0.00000093;
M = 1;
p = 0.1;
mu = 0.00001;
rho = 0.00002;
theta = 0.005;
omega = 0.05;
gamma = 0.001;
alpha1 = 0.0001;
alpha2 = 0.004;
S = X(1);
E = X(2);
I = X(3);
Q = X(4);
V = X(5);
F(1) = p*M – beta1*S*E – beta2*S*I – (rho + mu)*S;
F(2) = beta1*S*E + beta2*S*I – (omega + alpha1 + mu)*E;
F(3) = omega*E – (gamma + alpha2 + mu)*I;
F(4) = alpha1*E + alpha2*I – (theta + mu)*Q;
F(5) = (1 – p)*M + rho*S + gamma*I + theta*Q – mu*V;
end
function JF = jacobiano(X)
beta1 = 0.0000009;
beta2 = 0.00000093;
M = 1;
p = 0.1;
mu = 0.00001;
rho = 0.00002;
theta = 0.005;
omega = 0.05;
gamma = 0.001;
alpha1 = 0.0001;
alpha2 = 0.004;
S = X(1);
E = X(2);
I = X(3);
Q = X(4);
V = X(5);
JF = [-beta1*E – beta2*I – rho – mu, -beta1*S, -beta2*S, 0, 0;
beta1*E, beta1*S – (omega + alpha1 + mu), beta2*S, 0, 0;
0, omega, -(gamma + alpha2 + mu), 0, 0;
0, alpha1, alpha2, -(theta + mu), 0;
rho, 0, gamma, theta, -mu];
end
These are the codes of the two functions that qive the matrices
function [x, it, norma_diferenca] = metodo_newton2(F, JF, y0, e, nmax)
x = y0;
it = 0;
norma_diferenca = Inf;
while norma_diferenca > e && it < nmax
Fx = F(x);
JFx = JF(x);
div = JFx (-Fx);
x = x + div;
norma_diferenca = norm(div);
it = it + 1;
end
if it >= nmax
disp(‘Atingido o número máximo de iterações sem convergência.’);
end
end
And this is the code taht divide the two matrices. matlab, matrices, division MATLAB Answers — New Questions