Skip to content
Permalink
7f991220b3
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
34 lines (22 sloc) 769 Bytes
setdefaults;
m = 0.5; % mass in kg
g = 9.81; % acceleration due to gravity m/s^2
K = 30; %spring constant N/m
%Part a
collar_potential_energy = @(x_C, theta) m*x_C*g*sin(theta) + .5*K *((0.5 - sqrt(0.5^2+(0.5-x_C)^2)))^2;
%Part b
theta = 0;
[x1,fx1,ea1,iter1] = goldmin(collar_potential_energy,-10,10,0.0001,100,theta);
%Part c
theta = .9*pi/180;
thetaVec = linspace(0,pi, 400);
fx2 = 0;
[x3,fx3,ea3,iter3] = goldmin(collar_potential_energy,-10,10,0.0001,100,theta);
for i = 1:length(thetaVec)
theta = thetaVec(i);
[x2, fx2(i), ea2, iter2] = goldmin(collar_potential_energy, -10, 10, 0.0001, 100, theta);
end
plot(thetaVec, fx2);
title('Plot of Minimum PE for x_C with given Angle');
xlabel('Theta (radians)');
ylabel('x_C (meters)');