diff options
| author | Christian Kolset <christian@kolset.com> | 2021-07-09 23:50:15 -0600 |
|---|---|---|
| committer | Christian Kolset <christian@kolset.com> | 2021-07-09 23:50:15 -0600 |
| commit | 0f1c29b7c59ad4499168e0f521cf0522d01cc594 (patch) | |
| tree | 7a3265be4569dd6dd4bc3809232cd8a11f13e788 /Scripts | |
| parent | 34dd12861a9a90bf88ee9abc6d8398f93f1a7b01 (diff) | |
Added Functions and Scripts
Diffstat (limited to 'Scripts')
| -rw-r--r-- | Scripts/hw11/hw11.m | 29 | ||||
| -rw-r--r-- | Scripts/hw2/hw2.m | 60 | ||||
| -rw-r--r-- | Scripts/hw3/hw3.m | 37 |
3 files changed, 126 insertions, 0 deletions
diff --git a/Scripts/hw11/hw11.m b/Scripts/hw11/hw11.m new file mode 100644 index 0000000..312e816 --- /dev/null +++ b/Scripts/hw11/hw11.m @@ -0,0 +1,29 @@ +% Define problem constants +g = 9.81; +mu = 0.55; +F = 150; +m = 25; + +% Define the function to be solved for. Is the angle specified in radians or degrees? +%angle=@(-asin(g/(sqrt(mu^2)))+atand(mu)+((4*n2+1)*pi)/2 +func=@(angle) mu*m*g/(cosd(angle)+mu*sind(angle))-F; + +% THINK, what makes range sense for angle? +lower_bound=-90; +upper_bound=90; + +% Plot your function. Does plotting give you an idea about where the root is? +hold on +fplot(func) +fplot(0) + +% Finaly solve for the root using the bisection script given to you, which can be called as: +%[root, fx, ea, iter] = bisect(func, lower_bound, upper_bound); + +angle = bisect(func,lower_bound, upper_bound) + +% These variables will be checked for your final answer: +%angle = % the angle in degree that solves this problem +fx = func(angle) % the function value at your solved angle +ea = ea % the bisection error estimate +iter = iter % the number of bisection iterations
\ No newline at end of file diff --git a/Scripts/hw2/hw2.m b/Scripts/hw2/hw2.m new file mode 100644 index 0000000..6736240 --- /dev/null +++ b/Scripts/hw2/hw2.m @@ -0,0 +1,60 @@ +% Homework:2 +% Author: Christian Kolset +clear + +%% Part 1 + +% Function parameters +q0 = 10; +R = 60; +L = 9; +C = 0.00005; + +% Use linspace to create an array of 100 points between 0 and 0.8 +t = linspace(0,0.8); + +% Calculate the values of q +q = q0.*2.718.^(-R.*t/(2*L)).*cos(sqrt((1/(L*C))-(R/(2*L))^2).*t); + +% Plot q vs t +hold on +subplot(2,1,1) +plot (t,q,'b--*') +title('Capacity vs Time Graph') +xlabel('Time') +ylabel('Charge') +%legend('Charge','Time') +hold off + +% Make the capacitor 10x bigger +q2 = q0.*2.718.^(-R.*t/(2.*L)).*cos(sqrt((1/(L.*10.*C))-(R/(2.*L))^2).*t); + +% Plot q2 vs t +hold on +subplot(2,1,2) +plot(t,q2,'rs:') +title('10x Capacity vs Time Graph') +xlabel('Time') +ylabel('Charge') +%legend('Charge','Time') +hold off + +%% Part 2 +%{ +% Given experimental data +t_exp = 10:10:60; +c_exp = [3.4 2.6 1.6 1.3 1.0 0.5]; + +% Expected function +t_func = 0:0.5:70; +c_func = 4.84*2.718.^(-0.034*t_func); + +% Plot +hold on +plot(t_exp,c_exp,'rd:') +plot(t_func,c_func,'g--') +xlabel('Time [minutes]') +ylabel('Concentration [ppm]') +legend('Experimental','Predicted') +hold off +%}
\ No newline at end of file diff --git a/Scripts/hw3/hw3.m b/Scripts/hw3/hw3.m new file mode 100644 index 0000000..7caf82c --- /dev/null +++ b/Scripts/hw3/hw3.m @@ -0,0 +1,37 @@ +% HW3 +% Author: Christian Kolset +% Date: 20.5.21 + +%% HW3 +% Specify the variables needed to solve this problem (ie. height of each section, diameter, radiaus, ...) +% It is alwasy easier to work with variables (diameter_cyl = 25) than to use numbers everywhere, since a +% diameter indicates something specific but the number 25 could mean anything +diameter_Bot = 25; +r_bot = diameter_Bot/2; +h_cone = h-19; + +% Specify the height of the water +h = 20 +% You can comment / uncomment lines below for testing. This will overwrite the previous line for h = 20. +% For submission, make sure all of the following lines are commented out and h = 20! (OR IT IS MARKED AS WRONG) +%h = 5 +%h = 19 +%h = 47 +%h = -1 + +% Now compute the volume. Using conditional statments you will want to first check the height makes sense, +% and then solve the volume depending on what portion of the tank has been filled. +% Make sure that your volume is stored in the variable v! (OR IT WILL BE MARKED AS WRONG) +% You may find it more convenient to move v around in you code, it is only given here to indicate what variable to use. +%v = + +v_cyl = @(h,r_bot) pi*r_bot^2*h; +v_truncone = @(h_cone,r_bot) 1/3*pi*h_cone*(r_bot^2+r_bot*((h_cone+16.625)/1.33)+((h_cone+16.625)/1.33)^2); + +if h > 19 + v = v_cyl(19,r_bot)+v_truncone(h_cone,r_bot); +else + v = v_cyl(h,r_bot); +end + +fprintf(1,'Volume of Tank: %6.2f\n',v)
\ No newline at end of file |
