How can I generate a trigonometric formula for the following case?

7 visualizaciones (últimos 30 días)
M
M el 3 de Feb. de 2023
Respondida: John D'Errico el 3 de Feb. de 2023
How can I generate a trigonometric formula for the following case?
I want a formula that gives a certain value when I substitue an angle on it.
If there is the following angles in degree:
Theta= [39.8414239035357 38.0423831220740 35.9925962696569 33.6629179282453 31.0086860615562 27.9576609766453 24.3833553424339 20.0325913364901 14.2421123154231]
and these the values that should I got: (each angle gives a value)
Values= [0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000]
I mean if I substitue angle 39.8414239035357 on the formula it should give 0.1000 and so on ....
and if i substitue angle between two angle it should give the corresponding value
Note: I can increase the number of angle and it's corresponding value if that is needed.

Respuestas (3)

John D'Errico
John D'Errico el 3 de Feb. de 2023
Theta= [39.8414239035357 38.0423831220740 35.9925962696569 33.6629179282453 31.0086860615562 27.9576609766453 24.3833553424339 20.0325913364901 14.2421123154231];
Values= [0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000];
Is there an EXACT formula that generates those numbers? That would seem unlikely. And just because you have numbers that have units of degrees, nothing says that a trigonometric model will give you a great fit.
plot(Theta,Values,'-o')
Nothing stops you from trying though. For example, we might postulate a simple trigonometic model. Since these are clearly degrees, I'll use cosd. The curve fitting toolbox is a good choice for the fit.
mdl = fittype('a + b*cosd((Theta-shift)/c)','indep','Theta')
mdl =
General model: mdl(a,b,c,shift,Theta) = a + b*cosd((Theta-shift)/c)
fittedmdl = fit(Theta',Values',mdl,'start',[-0.2 1.1 0.4 10])
fittedmdl =
General model: fittedmdl(Theta) = a + b*cosd((Theta-shift)/c) Coefficients (with 95% confidence bounds): a = -17.72 (-876, 840.6) b = 18.67 (-839.7, 877.1) c = 1.952 (-43.77, 47.68) shift = 6.301 (-5.046, 17.65)
plot(fittedmdl,Theta,Values)
And, while it seems to fit, the parameters look a bit strange.
Honestly, you would be as good using a spline to interpolate your curve nice and smoothly, or using a simple polynomial model. Again, just beccaue those are degees does not mean a trig based model is appropriate.
P3 = fit(Theta',Values','poly3')
P3 =
Linear model Poly3: P3(x) = p1*x^3 + p2*x^2 + p3*x + p4 Coefficients (with 95% confidence bounds): p1 = -1.429e-05 (-1.87e-05, -9.872e-06) p2 = 0.0003809 (2.039e-05, 0.0007414) p3 = -0.01812 (-0.02746, -0.008775) p4 = 1.123 (1.047, 1.199)
plot(P3,Theta,Values)
So an entirely reasonable model, as good, if not better than the trig model in terms of a fit. Don't try to force a model into a specific form just because of preconceptions that it MUST be a trig model because degrees were involved.

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 3 de Feb. de 2023
Editada: Sulaymon Eshkabilov el 3 de Feb. de 2023
Here is how this can be solved using syms and vpasolve:
Theta= [39.8414239035357 38.0423831220740 35.9925962696569 33.6629179282453 31.0086860615562 27.9576609766453 24.3833553424339 20.0325913364901 14.2421123154231] ;
Values= [0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000];
T = (Theta).';
b = Values.';
plot(T, b, 'k*'), hold on
Solution = fit(T, b, 'poly3')
Solution =
Linear model Poly3: Solution(x) = p1*x^3 + p2*x^2 + p3*x + p4 Coefficients (with 95% confidence bounds): p1 = -1.429e-05 (-1.87e-05, -9.872e-06) p2 = 0.0003809 (2.039e-05, 0.0007414) p3 = -0.01812 (-0.02746, -0.008775) p4 = 1.123 (1.047, 1.199)
plot(Solution), grid on
legend('Data', 'Fit Model')
%The variable x stands for "Theta" in your given exercise, in other words:
% Solution(Theta) = (-1.429e-05)*Theta.^3 + 0.0003809*Theta.^2 + (-0.01812)*Theta + 1.123;
  2 comentarios
M
M el 3 de Feb. de 2023
@Sulaymon Eshkabilov Thanks, but it doesnt make sense to substitue the angles as a number X , is there any other formula that contains a trigonometric representation ?
Sulaymon Eshkabilov
Sulaymon Eshkabilov el 3 de Feb. de 2023
Do you understand in the polynomial equation shown above what x stands for?
The variable x stands for "Theta" in your given exercise, in other words: Solution(Theta) = (-1.429e-05)*Theta.^3 + 0.0003809*Theta.^2 + (-0.01812)*Theta + 1.123;

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 3 de Feb. de 2023
Movida: Image Analyst el 3 de Feb. de 2023
Try this:
Theta= [39.8414239035357 38.0423831220740 35.9925962696569 33.6629179282453 31.0086860615562 27.9576609766453 24.3833553424339 20.0325913364901 14.2421123154231] ;
Values= [0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000];
plot(Theta, Values, 'b*', 'MarkerSize', 20, 'LineWidth', 2)
hold on
xlabel('Theta');
ylabel('Values')
% Fit data to a 5th order polynomial.
coefficients = polyfit(Theta, Values, 5)
coefficients = 1×6
-0.0000 0.0000 -0.0002 0.0032 -0.0426 1.1917
% Compute smooth fit with 500 points.
xFit = linspace(min(Theta), max(Theta), 500);
yFit = polyval(coefficients, xFit);
plot(xFit, yFit, 'r-', 'LineWidth', 2)
grid on
legend('Data', 'Fit Model')
You are only showing a small window of data, and in that window, a third order polynomial fits well. The thing to ask is if your predictions from the model seem reasonable. As I hope you know trig functions like sin and cosine can be modeled by Taylor series of odd power, or even power, polyjnomials respectively. So fitting to a polynomial is just like fitting to a sine or cosine, at least in that window you've shown.
If you have more cycles way outside that window and your data is wavy, then you can use fitnlm to fit your data to a pure sine or cosine model.

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by