I wrote a script with 3 parts to simulate a hockey puck bouncing around on a plot.
%Part 1: main body of script
hf=figure;
ha=axes('Parent',hf);
hp=plot(ha,0,0,'o','LineWidth',5);
axis([0 5 0 2]);
pos = [0,0]
vel = [1,1]
for step = 1:.02:1000
set (hp,'XData',pos(1))
set (hp,'YData',pos(2))
pos = pos_vel(pos,vel)
[pos,vel]= Reflect(pos,vel)
Part 2: kinematics function to update pos and vel of puck
function [ new_pos ] = pos_vel(pos,vel,dt)
dt = .5;
new_pos = pos + vel*dt
end
Part 3: keeps puck in boundaries of (x,y) = from (0,0) to (5,2)
function [pos,vel] = Reflect(pos,vel)
if pos(1) >= 5
pos(1) = 10-pos(1)
vel(1) = -vel(1)
end
if pos(1)<=0
pos(1) = -pos(1)
vel(1) = -vel(1)
end
if pos(2) >= 2
pos(2) = 4-pos(2)
vel(2) = -vel(2)
end
if pos(2)<= 0
pos(2) = -pos(2)
vel(2) = -vel(2)
end
end
When I try to run I get msg: "Undefined function 'pos_vel' for input arguments of type 'double'.
Error in Lab_13_Revised (line 12) pos = pos_vel(pos,vel)"
Is this a problem with the file path or with the code? I have tried the mkdir and addpath commands and it still is not working.