3rd order approximation solving for variable
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jose Iglesias
el 22 de Mzo. de 2023
Respondida: John D'Errico
el 22 de Mzo. de 2023
I am using a 3rd order approximation to solve the equation shown below:with the x values representing input voltages and y values representing measured output voltages.I need asistance in solving for Vin with Vo given as .956V
Vo = Co + C1*Vin +C2*Vin^2+C3*Vin^3
I solved for Co,C1,C2,and C3 with the following Matlab code
x = (0.2:0.2:0.8);
y = [.3168, .7404, 1.3736, 2.2692];
p = polyfit(x,y,3)
This code gave me the following values which I know are correct.
Co =1.1
C1 = 1.3
C2 = 1.03
C3 = 0.05
I tried to solve for Vin using the following code but it does not give me the correct answer since the Vin is supposed to be Vin = 0.475
equation = [0.05 1.03 1.3 1.1 -.956];
roots(equation)
I do not get Vin = .475 with the previous code and this code gives me 4 different answers for Vin . The original problem statement is shown below. I need assistance in creating the code to solve for Vin. Thanks you in advance!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1333500/image.png)
0 comentarios
Respuesta aceptada
John D'Errico
el 22 de Mzo. de 2023
x = (0.2:0.2:0.8);
y = [.3168, .7404, 1.3736, 2.2692];
format long g
p = polyfit(x,y,3)
So, to within floating point trash, those were the coefficients.
However you then did this:
equation = [0.05 1.03 1.3 1.1 -.956];
WRONG!!!!!!!
How many elements are in that vector of coefficients? 5.
numel(equation)
You created a FOURTH degree polynomial.
Do you not see there is a difference between what you did, and this?
equation2 = [0.05 1.03 1.3 1.1-.956];
numel(equation2)
That extra space in there is important. It is best to get into the havit of putting commas vbetween number, and to be CAREFUL about spaces there.
But worse, WHY DID YOU FLIP THE COEFFICIENTS AROUND? Polyfit returns the HIGHEST order coefficient first. In order to do what you want, you need to subtract off from the CONSTANT term. But if you flip the coefficients around, the result will be garbage. You need to do this:
equation3 = [1.1, 1.3, 1.03, 0.05-.956]
And NOW, roots will work.
roots(equation3)
Remember, this is a CUBIC polynomial. So there will be three roots. The third root is the one you probably wanted, as it is the real root.
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!