Question

Overview: In this exercise, you will be writing a function that finds what spring constant k is required in order to minimise

0 0
Add a comment Improve this question Transcribed image text
Answer #1

MATLAB Script:

close all
clear
clc

data = [0.1, 2.26; 0.2, 4.43; 0.3, 5.85; 0.4, 8.42; 0.5, 9.91; 0.6, 11.97];
guess_k = 0.058;
RMSE = rmse(data, guess_k); % RMSE before applying rmseMin2()
fprintf('RMSE (with guessed value of k = %.4f) = %.4f\n', guess_k, RMSE)

best_k = rmseMin2(data, guess_k);
RMSE = rmse(data, best_k); % RMSE after applying rmseMin2()
fprintf('RMSE (with best value of k = %.4f) = %.4f\n', best_k, RMSE)
disp('Hence, there''s clearly an improvement as can be seen from reduced RMSE.')

function best_k = rmseMin2(data, guess_k)
Func = @(k) rmse(data, k);
best_k = fminsearch(Func, guess_k);
end

function RMSE = rmse(data, k)
% x = F/k
% where F = force (column 1), x = displacement (column 2)
  
x_measured = data(:,2); % second column
x_theoretical = data(:,1)/k; % F/k
RMSE = sqrt(sum((x_measured - x_theoretical).^2)/length(x_measured));
end

Output:

RMSE (with guessed value of k = 0.0580) = 1.1786
RMSE (with best value of k = 0.0496) = 0.2671
Hence, there's clearly an improvement as can be seen from reduced RMSE.

Add a comment
Know the answer?
Add Answer to:
Overview: In this exercise, you will be writing a function that finds what spring constant k...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • matlab help plz Overview: In this exercise, you will write code to compare how two different mumerical methods (a mi...

    matlab help plz Overview: In this exercise, you will write code to compare how two different mumerical methods (a middle Riemann sum, and MATLAB's integral function) evaluate the function fx) and the x-axis. The code should output the error between the two calculated areas. area between a Function Inputs Func- the function to be numerically integrated. a-the lower interval value. b-the upper interval value. N-the number of rectangles to be used. Function Outputs: Area Riemann- the numerical approximation for the...

  • 4. Consider the mechanical system shown below with a spring with stiffness, k (N/m), in parallel...

    4. Consider the mechanical system shown below with a spring with stiffness, k (N/m), in parallel with a viscous damper with coefficient, h (Nós/m) and an externally applied force, Fexi(t) (N). u(t) a. Find the equation that relates the applied force, Fext(t) and the displacement, u(t). b. If the spring component has a stiffness of k = 75 N/m, the damper component has coefficient h = 50 N s/m and the externally applied force is a constant 4.5 N applied...

  • Given these values, how would you report the best estimate spring constant (K) with uncertainty? Note:...

    Given these values, how would you report the best estimate spring constant (K) with uncertainty? Note: Holder height = x (displacement from equilibrium) like in the equation for Hooke's law F = -k(x) when plotted on a graph, these values produce this equation (best-fit line) ... Thank you Holder Height (m) Force (N) Standard deviation (holder height) 0.4348 0.3989 0.363 0.3272 0.2907 0.49 0.686 0.882 1.078 1.274 0.000398:3 0.001153 0.001119 0.002475 0.004052 y =-5.4459x +2.8584

  • A student uses a rectangular carrot cantilever beam to find the spring constant, k, to determine...

    A student uses a rectangular carrot cantilever beam to find the spring constant, k, to determine its Youngs modulus. 10g increments are added to the apparatus and the displacement is measured each time. a. Using the data provided, plot a graph of F (applied force in N) on the y axis versus x (displacement of cantilever in mm) on the x axis. Include: - Horizontal error bars - Line of best fit – Two lines of worst fit b. Find...

  • please solve then upload matlab code Thanks 1. The function f(z, y) (a-x)2 + b(y-12)2 is...

    please solve then upload matlab code Thanks 1. The function f(z, y) (a-x)2 + b(y-12)2 is called Rosenbrock's banana function. It is often used as a benchmarking test for optimization algorithms becatse it is easy to find the minimum by hand but often very difficult to find numerically. Throughout the problem, we will use the values a = 2 and b 10. You can plot this function using the following code: x3:0.1:3; y = -10:0.2:10; Cx,Ymeshgrid(x,y); Z(2-X).2 10* (Y-X. 2)....

  • isfy the linear equation Fkx+F where k is the spring constant and F is the preload induced during manufactur problem P13. igure P13 Close-wound tension spring for (a) Using the given data in Fig...

    isfy the linear equation Fkx+F where k is the spring constant and F is the preload induced during manufactur problem P13. igure P13 Close-wound tension spring for (a) Using the given data in Fig P12 find the equation of the line for the spring force F as a function of the displacement x, and determine the values of the spring constant k 1-4. In a bolted connection shown in Fig. P14, the force in the bolt F is given in...

  • photo of the code please and an explnation if possible, Construct a simple MATLAB function program...

    photo of the code please and an explnation if possible, Construct a simple MATLAB function program my_factorial which calculates product of first n positive integer numbers (i.e. find factorial n!). For full points: - Make sure you protect the code from illogical use (n must be positive integer) - Test the function by comparing with built in MATLAB function factorial(n) - Make sure you test your function for any limitations. O marks) -3. Using my factorial function from the previous...

  • 1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector...

    1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code. b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19...

  • In this exercise, you will create a function trough_plot which will plot the cross-section of a...

    In this exercise, you will create a function trough_plot which will plot the cross-section of a trough outlines by the functions y0 and y. Input variables: x – a vector representing the x co-ordinates for the outline of the trough. y – a vector representing the y co-ordinates for the bottom of the trough. y0 – a vector representing the y co-ordinates for the top of the trough. Output variable: n/a – this function has no output variables. Process: The...

  • 10 springs have been tested and have had their spring constant recorded. This data has been...

    10 springs have been tested and have had their spring constant recorded. This data has been provided in a csv file 10.051, 9.5551, 9.806, 9.9991, 10.191, 10.259, 9.8472, 9.4386, 9.4493, 9.5575 1. Using MATLAB, import the data using csvread and determine the sample mean and variance using in built functions is fine)(finished) 2. Determine the 95% confidence interval for the spring constant of the springs finished) x = csvread("values csv") m = mean(x); v = var(x); sprintf ("Mean is %f...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT