Skip to content
Permalink
master
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

Homework #3

i. Compare the number of iterations that each function needed to reach an accuracy of 0.00001%. Include a table in your README.md with:

| solver | initial guess(es) | ea | number of iterations|
| --- | --- | --- | --- |
|falsepos   |85,100  | 0.0116 | 50 |
|incsearch  | 85,90 | 8.7659e-05 | 16 |
|newtraph   | 100-(h(80)*(80-100))/(h(80)-h(100)),100 |  8.0459e-05 | 6 |
|mod_secant | @projectile,@dprojectile_theta, 90 | 8.0023e-5 | 4 |

ii. Compare the convergence of the 4 methods. Plot the approximate error vs the number of iterations that the solver has calculated. Save the plot as convergence.png and display the plot in your README.md with:

![Plot of convergence for four numerical solvers.](convergence.png)

iii. In the README.md provide a description of the files used to create the table and the convergence plot.

divergence of Newton-Raphson method

iteration x_i approx error
0 2 n/a
1 0.3678
2 0.0366
3 3.70e-4
4 4.50e-7
5 6.94e-11

Homework #4

Part A

function PE = collar_potential_energy(x,theta).

theta_d = theta*180/pi;

x_C = 0.5+x;

         %spring length when the spring is unstretched.

         %positive x means the collar move away from point o.
         
          %negative x means the collar move towards the point o.

m = 0.5;

%mass of the collar.

g = 9.81;

%unit m/s^2 .

K = 30;

%spring stifness unit of N/m.

PE_g = mgx_C*sin(theta_d);

                       %Potential energy equation due to gravity.

                       %which 'theta' is the angle between the collar.
                       
                       %and the horizontal ground.

DL = 0.5-sqrt(0.5^2+(0.5-x_C)^2);

PE_s = 0.5K(DL)^2;

%Potential energy equation due to the spring.

PE_tol = PE_g + PE_s

%Total energy equation.

end

Part b

function PE = xcollar_potential_energy(x)

theta_d = 0*180/pi;

x_C = 0.5+x;

         %spring length when the spring is unstretched
        
         %x is the distance that collar moves
        
         %positive x means the collar move away from point o
        
         %negative x means the collar move towards the point o

m = 0.5; %mass of the collar

g = 9.81; %unit m/s^2

K = 30; %spring stifness unit of N/m

PE_g = mgx_C*sin(theta_d);

          %Potential energy equation due to gravity,
                     
          %which 'theta' is the angle between the collar 
                     
          %and the horizontal ground.

DL = 0.5-sqrt(0.5^2+(0.5-x_C)^2);

PE_s = 0.5K(DL)^2; %Potential energy equation due to the spring

PE_tol = PE_g + PE_s %Total energy equation.

end

Using goldmin function, it gives us the minimum potential energy is 0, at x_c = 0

#Part C

g = 9.81; %unit m/s^2

m = 0.5;

K = 30; %spring stifness unit of N/m

for x = -1:0.1:1

x_C = 0.5+x

for theta = 0:90

theta_d = theta*180/pi;

PE_g = m*g*x_C*sin(theta_d);

end

DL = 0.5-sqrt(0.5^2+(0.5-x_C)^2);

PE_s = 0.5*K*(DL)^2;

PE_tol = PE_g + PE_s

end

From for loop function, the minimum potential energy happens at x_c = 0, the total potential energy = 0.6434