unable to perform assignment becuase the left and right sides have a different amount of elements HELPPP!!
    2 次查看(过去 30 天)
  
       显示 更早的评论
    
f1=@(x,y1,y2) (-6*y2-5*y1)/.5
f2=@(x,y1,y2) diff(y1)
% Condiciones iniciales -----------------------------------------------
%y1(0)=1;
%y2(0)=0;
x=0
xn=5
y1=1
y2=0
h=0.5
% Método de RK4Orden ---------------------------------------------------
while x(end)<=xn
    k11= f1(x(end),y1(end),y2(end)); 
    k12= f2(x(end),y2(end),y2(end)); 
    k21= f1(x(end)+.5*h,y1(end)+.5*k11*h,y2(end)+.5*k12*h);
    k22= f2(x(end)+.5*h,y1(end)+.5*h*k11,y2(end)+.5*h*k12);
    k31= f1(x(end)+.5*h,y1(end)+.5*k21*h,y2(end)+.5*k22*h);
    k32= f2(x(end)+.5*h,y2(end)+.5*k22*h,y2(end)+.5*k22*h);
    k41= f1(x(end)+h,y1(end)+k31*h,y2(end)+k32*h);
    k42= f2(x(end)+h,y2(end)+k32*h,y2(end)+k32*h);
    x(end+1)=x(end)+h;
    y1(end+1)=y1(end)+1/6*(k11+2*k21+2*k31+k41)*h;    
    y2(end+1)=y2(end)+1/6*(k12+2*k22+2*k32+k42)*h;   
end
plot(x,y1)
4 个评论
  Walter Roberson
      
      
 2022-6-16
				You follow the guidance I gave at https://www.mathworks.com/matlabcentral/answers/1741615-why-is-it-not-plotting-or-graph-it-comes-out-blank#answer_986690 
  Jeffrey Clark
      
 2022-6-16
				Two more lines like k12 need fixing:
k32= f2(x(end)+.5*h,y2(end)+.5*k22*h,y2(end)+.5*k22*h);
k42= f2(x(end)+h,y2(end)+k32*h,y2(end)+k32*h);
回答(0 个)
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



