I don't understand why the elements are not the same on both sides
    6 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Syed Shah
 el 26 de Feb. de 2021
  
    
    
    
    
    Respondida: Star Strider
      
      
 el 26 de Feb. de 2021
            >> N = 200;
h=tFinal/N;
t=linspace(0,tFinal,N+1); % type 'help linspace' to see how this works
z=zeros(1,N+1);
z(1)=1;
for n=1:N
    z(n+1) = z(n) + h * ((10*(t(n)+1)^8/((t(n)+1)^10.+9)));
end
for n=1:N
    x(n+1) = x(n) + h * ((8*(x(n))/(t(n)+1))-(t+1)*(x(n)^2));
end
plot(t,z,'--')
xlabel('t'); ylabel('y'); title('Look, ma! I solved it even better!');
Unable to perform assignment because the left and right sides have a different number of
elements.
0 comentarios
Respuesta aceptada
  Star Strider
      
      
 el 26 de Feb. de 2021
        The reason is that ‘t’ needs a subscript: 
x(n+1) = x(n) + h * ((8*(x(n))/(t(n)+1))-(t+1)*(x(n)^2));
                                          ↑ ← HERE
so: 
x(n+1) = x(n) + h * ((8*(x(n))/(t(n)+1))-(t(n)+1)*(x(n)^2));
works.  
Using ‘t’ without a subscript uses the entire vector.  Using ‘t’ with a subacript uses only that one element.  
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!