2017-11-23 1 views
0

Xdot와 관련하여 정수 L을 플로팅하려하지만 벡터 길이가 같아야합니다. 그러나 문제를 해결하는 방법을 모르겠습니다. 내 코드는 아래와 같습니다. X_1 내가 그러나 루프를 변경하면, 나는 오류가 100까지가는 동안벡터의 길이가 같아야합니다.

% The solution for this part is based on the Euler method 

    f=0;  %initializing the force row vector 
    f_1=0.5; %initializing the first derivative of force 
    x=1;  % intializing the mass displacement% 
    x_1(1)=0;  % initializing the first derivative of mass displacement 
    t=0;  % initializing the time row vector 
    j=1;   % initializing a`enter code here`n index used in iterations 
    a=0; 
    b=10; 
    N=100; 
    h=(b-a)/N; 


for j = 0:N-1 

f_2=-1*sin(f);  %obtain the second derivative of the force 

f_1=f_1+f_2*h;  %obtain the first derivative of the force 

f=f+f_1*h; % obtain the value of force and concatenate it with 
        %preceding force row vector the element 

x_2=f-0.1*x_1-x-x^3; %obtain the second derivative of the mass displacement 

x_1=x_1+x_2*h;    % obtain the first derivative of the mass displacement 

x=x+x_1*h; % obtain the current value of mass displacement and 
        %concatenate it with preceding mass displacement row vector the element 

t=t+h; % obtain the current value of time and concatenate it with 
        %preceding time row vector the element  
j=j+1; %increment the index iterator by one 

v(j)=x; 
w(j)=t; 
m(j)=x_1 
end 

sum = 0; %%Trapezoidal method to find L, sum is L, put this at the end of your script 
for i = 1:size(m,2)-1 
    sum = sum + h*(m(i+1)^2+m(i)^2)/2; 
    L(i) = sum 
end 

plot (m,L, 'r') 

답변

4

"지수는 매트릭스 크기를 초과", 합계의 루프는 99 층까지, 하단에 볼 수 있습니다 플롯 할 때 x을 하나 줄여보십시오.

plot (m(1:end-1),L, 'r') 
관련 문제