MATLAB: Not sure how to graph y(h) vs z(h)

graph

clear;clc;
i = 0;
f = 60;
L = 30;
E = (1.25*10^8);
I = 0.05;
z0 = 0;
u0 = 0;
R = f/(2*E*I);
hold on;
for h = 1:1:30
k1(i+1) = u0;
l1 = R * (L - z0)^2;
k2 = u0+(h/2)*l1;
l2 = (R)*(L- (z0 +(h/2)))^2;
k3 = u0 +l2/2;
l3 = (R)*(L - (h/2))^2;
k4 = u0 + h*(l3);
l4 = R* (L - h)^2;
y(h) = u0 + (h/6)*(k1+2*(k2+k3)+k4);
z(h) = z0 +(h/6)*(l1+2*(l2+l3)+l4);
plot(y(h),z(h))
y_true = R * (L - h)^2;
Error = (abs((y_true - y(i+1)))/y_true)*100;
end
hold off;
I am trying to graph the y(h) vs z(h) and it is not working. Not sure what the appropriate syntax is for it. I am new to Matlab and came over from C++

Best Answer

i = 0;
f = 60;
L = 30;
E = (1.25*10^8);
I = 0.05;
z0 = 0;
u0 = 0;
R = f/(2*E*I);
N = 30 ;
y = zeros(N,1) ;
z = zeros(N,1) ;
for h = 1:1:N    
    k1 = u0;
    l1 = R * (L - z0)^2;
    k2 = u0+(h/2)*l1;
    l2 = (R)*(L- (z0 +(h/2)))^2;
    k3 = u0 +l2/2;
    l3 = (R)*(L - (h/2))^2;
    k4 = u0 + h*(l3);
    l4 = R* (L - h)^2;
    y(h) = u0 + (h/6)*(k1+2*(k2+k3)+k4);
    z(h) = z0 +(h/6)*(l1+2*(l2+l3)+l4);    
      y_true = R * (L - h)^2;
      Error = (abs((y_true - y(i+1)))/y_true)*100;
  end
  plot(y,z) ;