Finding inverse quadratic equation

Hi, I'm trying to find a quadratic equation to express Force in terms of voltage (Force=a*(voltage)^2+b*(voltage)+c) for FSR sensors.
Currently, using the data I've collected , I managed to plot graph for Voltage output based on force applied. Then, I've found the equation for Voltage in terms of Force using the Polyfit. Basically, the known values is force applied in Newton and the corresponding is Voltage values based on Force.
I've tried using 'finverse' function in Matlab, however for linear only it works for quadratic it doesn't. The force need to increase as voltage increases, but using 'finverse' the force decreases as voltage increases. Another problem is that, at zero voltage, the force is supposed to be zero too but I couldn't get this.
The second method that I'm trying out is using 'solve()'. But I am unsure of how to use this. Can anyone guide me how to use solve() to get the quadratic equation? And is there another way to get the equation?
My code is attached here. Thank you

4 件のコメント

KSSV
KSSV 2018 年 7 月 2 日
Copy paste the code....attaching code as image snippet is useless...
FADLINA DIYANA
FADLINA DIYANA 2018 年 7 月 2 日
Oh sorry about that. Thank for the heads up . here's the code
clc;
clear all;
%%Reading data from Excel
A = (xlsread('Calibration1','Sheet1','A2:A13')); %%Force in (N)
B = xlsread('Calibration1','Sheet1','B2:B13'); %%Voltage in (V)
%%Finding the y=mx+c for 3rd order
p=polyfit(A,B,2) %to get fit parameter
coef1 = polyfit(A,B,2);
y1 = polyval(coef1,A);
%%Plotting graph of voltage against arduino force
hold on
plot(A,B);
xlim ([0, 100])
ylim ([0, 2.5])
grid minor
xlabel('Force (N)')
ylabel('Voltage(V)')
title('Graph of Voltage against Force for 2.7kOhm')
%%Plotting graph for the polyfit of quadratic and cubic to compare
syms x
f(x) = (-0.000002710001545*x^3)+(0.000263965736402*x^2)+(0.022271515076853*x) -0.110573119933342;
plot( A , f([A]))
syms z
h(z) = (-0.000139980334195*z^2)+(0.037429843355943*z)-0.197985057305680;
plot(A, h([A]))
%%Using solve to get the Final Equation
solz=solve((-0.000139980334195*z^2)+(0.037429843355943*z)-0.197985057305680,z)
S=solve(h,z,'MaxDegree',2);
%%Finding inverse
w = finverse(h) %finding the inverse of the function
FADLINA DIYANA
FADLINA DIYANA 2018 年 7 月 2 日
And this is the calibration data to run the code.
Torsten
Torsten 2018 年 7 月 2 日

サインインしてコメントする。

回答 (0 件)

カテゴリ

質問済み:

2018 年 7 月 2 日

コメント済み:

2018 年 7 月 2 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by