2017-11-23 153 views
0

私は積分LをXdotに関してプロットしようとしていますが、ベクトルを同じ長さのエラーにする必要がありますが、それを修正する方法はわかりません。私のコードは以下の通りです。 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を1つ短くするのはどうですか?

plot (m(1:end-1),L, 'r') 
関連する問題