From 26f9500d3fe5073788354102d157cc5e7978c740 Mon Sep 17 00:00:00 2001 From: Christian Kolset Date: Sat, 21 Dec 2024 20:11:19 +0100 Subject: Renamed and re-organized files in Scripts/ directory --- Scripts/README.md | 17 +++++++++++++++ Scripts/hw02.m | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Scripts/hw02/hw2.m | 60 ----------------------------------------------------- Scripts/hw03.m | 37 +++++++++++++++++++++++++++++++++ Scripts/hw03/hw3.m | 37 --------------------------------- Scripts/hw11.m | 29 ++++++++++++++++++++++++++ Scripts/hw11/hw11.m | 29 -------------------------- Scripts/hw2/hw2.m | 60 ----------------------------------------------------- Scripts/hw3/hw3.m | 37 --------------------------------- 9 files changed, 143 insertions(+), 223 deletions(-) create mode 100644 Scripts/README.md create mode 100644 Scripts/hw02.m delete mode 100644 Scripts/hw02/hw2.m create mode 100644 Scripts/hw03.m delete mode 100644 Scripts/hw03/hw3.m create mode 100644 Scripts/hw11.m delete mode 100644 Scripts/hw11/hw11.m delete mode 100644 Scripts/hw2/hw2.m delete mode 100644 Scripts/hw3/hw3.m (limited to 'Scripts') diff --git a/Scripts/README.md b/Scripts/README.md new file mode 100644 index 0000000..2e8e64f --- /dev/null +++ b/Scripts/README.md @@ -0,0 +1,17 @@ +# [Scripts](Scripts) +This directory contains the scripts to solve the homeworks assignments below: + +## hw02.m +Both part 1 and part 2 on the excercise are writen in the script. When the script is run part 2 will be skipped. To run part 2, put part 1 in comments and uncomment part 2. To uncomment remove the `%{` and `%}` (line 43 and 70) to prevent the MATLAB interpreter to skip the code. + +### Part 1 +Creates a supplots of two graphs. The first plot shows the charge on a capacitor in an electrical circuit. First graph ranges from t = 0 to 0.8 witj, q0=10, R=60, L=9, and C=0.00005. A second plot shows a capacitor with 10 times greater charge (C=0.0005) + +### Part 2 +Creates a plot displaying the measured data (red diamond shapes) and the expected function (green dashed line). Ranges from 0 to 70 minutes using a a step size of 30 seconds. + +# hw03.m +This script solves the volume in a tank with the shape of a cylinder with a tuncated cone on top. This script should be turned into a function to solve the volume of a tank with any given the height of cylinder and truncated cone, and diameter of both the cylinder and top of the truncated cone. + +## hw11.m +Script to solve the angle of which to pull a 25 kg block with 150 N using the bisection method of finding roots. diff --git a/Scripts/hw02.m b/Scripts/hw02.m new file mode 100644 index 0000000..6736240 --- /dev/null +++ b/Scripts/hw02.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/hw02/hw2.m b/Scripts/hw02/hw2.m deleted file mode 100644 index 6736240..0000000 --- a/Scripts/hw02/hw2.m +++ /dev/null @@ -1,60 +0,0 @@ -% 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/hw03.m b/Scripts/hw03.m new file mode 100644 index 0000000..7caf82c --- /dev/null +++ b/Scripts/hw03.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 diff --git a/Scripts/hw03/hw3.m b/Scripts/hw03/hw3.m deleted file mode 100644 index 7caf82c..0000000 --- a/Scripts/hw03/hw3.m +++ /dev/null @@ -1,37 +0,0 @@ -% 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 diff --git a/Scripts/hw11.m b/Scripts/hw11.m new file mode 100644 index 0000000..312e816 --- /dev/null +++ b/Scripts/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/hw11/hw11.m b/Scripts/hw11/hw11.m deleted file mode 100644 index 312e816..0000000 --- a/Scripts/hw11/hw11.m +++ /dev/null @@ -1,29 +0,0 @@ -% 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 deleted file mode 100644 index 6736240..0000000 --- a/Scripts/hw2/hw2.m +++ /dev/null @@ -1,60 +0,0 @@ -% 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 deleted file mode 100644 index 7caf82c..0000000 --- a/Scripts/hw3/hw3.m +++ /dev/null @@ -1,37 +0,0 @@ -% 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 -- cgit v1.2.3