I am writing code for a spring mass damper system and everything looks right compared to the book but I am getting an error "Undefined function or variable 't'." When I define the variable 't' it then goes to give me an error for 'y' and likewise for 'z'. The book does not define any variable so I am left confused on what is wrong. This is my first semester using Matlab and any help would be appreciated.
>> SpringMassDamperProject(t, y, z)Undefined function or variable 't'.function y = SpringMassDamperProject(t,y,z)y = [y(2);-2*z*y(2)-y(1)];z = [0.1,1.0,5.0];lintype = char('-k','--k','-.k');tspan = linspace(0,40,400);for n = 1:3 [t,y] = ode45(@SpringMassDamperProject,tspan,[1 1]',[],z(n)); figure(1); plot(t,y(:,1),lintyp(n,:)); hold on figure(2); plot(y(:,1),y(:,2),lintyp(n,:)); hold onendfigure(1)xlabel('\time');ylabel('y(\time)');axis([0,40,-1.5,1.5]);plot([0,40],[0,0],'k-')legend('\z=0.1','\z=1.0','\z=5.0')figure(2)xlabel('Displacement');ylabel('Velocity');legend('\z=0.1','\z=1.0','\z=5.0',2)axis([-1.5,1.5,-1.5,1.5]);end
Best Answer