The transfer function of a small position Sensor
Show older comments
I have the below matlab code and I would like to find :
- First Order Fit: try (polyfit), Find the Matlab function for fitting: P = WHAT_FUNCTION(WHAT TO FIT as what is x, WHAT TO FIT as what is y, ORDER); Force_Nm_Linear = P(1) * Displacement_d_mm + P(2);
- Second Order Fit, same as above: what is x, y, ORDER P = WHAT_FUNCTION(WHAT TO FIT, WHAT TO FIT, ORDER); Force_Nm_2nd_Order = P(3) + P(2)*Displacement_d_mm + P(1)*Displacement_d_mm.*Displacement_d_mm;
Note: we have to set some of the coefficients to = 0 to check if it can be ignored:
P(3) = 0;
Force_Nm_2nd_two_Terms = P(3) + P(2)*Displacement_d_mm + P(1)*Displacement_d_mm.*Displacement_d_mm;
My Matlab code is::::::::::::::::
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;
close all;
clc;
Displacement_d_mm = [0, 0.08, 0.16, 0.24, 0.32, 0.4, 0.48, 0.52];
Force_Nm = [0, 0.578, 1.147, 1.677, 2.187, 2.648, 3.089, 3.295];
% Part A: First Order Fit:
% In this case, x is the displacement and y is the force.
% where d is the displacement and F the force
P = polyfit(Displacement_d_mm, Force_Nm, 1);
Force_Nm_Linear = P(1) * Displacement_d_mm + P(2); % F = 6.3221d + 0.089
% Part B:
Displacement_d_mm_b = [0, 0.32, 0.52];
Force_Nm_b = [0, 2.187, 3.295];
% Second Order Fit:
P = polyfit(Displacement_d_mm, Force_Nm, 2);
Force_Nm_2nd_Order = P(3) + P(2)*Displacement_d_mm + P(1)*Displacement_d_mm.*Displacement_d_mm;
Accepted Answer
More Answers (0)
Categories
Find more on Linear Model Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!