Error using / Matrix dimensions must agree
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Daren Wade
el 4 de Oct. de 2019
N = 10;
h=tFinal/N;
t=linspace(0,tFinal,N+1); % type 'help linspace' to see how this works
y=zeros(1,N+1);
yExact=9/((3.*t-1+10.*exp(-3.*t)));
y(0) = 1; % setting the initial condition
for n=1:N
y(n+1) = y(n) + h * y(n)*(3-t*y(n));
end
plot(t,y,t,yExact,'--')
xlabel('t'); ylabel('y'); title('Look, ma! I solved another ODE in MATLAB!');
error10= abs(y(N+1)-yExact(N+1));
0 comentarios
Respuesta aceptada
Adam Danz
el 4 de Oct. de 2019
Editada: Adam Danz
el 4 de Oct. de 2019
There's not enough information in your question to know what line is producing the error but I'll go out on a limb and guess that it's this one
yExact=9/((3.*t-1+10.*exp(-3.*t)));
assuming that the divisor is a row vector.
Example:
9/(1:6)
Error using /
Matrix dimensions must agree.
If your intension is to divide a scalar by each element of a vector,
yExact=9 ./ ((3.*t-1+10.*exp(-3.*t)));
% ^ dot
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!