Permalink
Cannot retrieve contributors at this time
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?
roots_and_optimization/HW4_Work
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
34 lines (22 sloc)
769 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)'); | |