How can I generate a trigonometric formula for the following case?
조회 수: 2 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (3개)
John D'Errico
2023년 2월 3일
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')
fittedmdl = fit(Theta',Values',mdl,'start',[-0.2 1.1 0.4 10])
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')
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.
댓글 수: 0
Sulaymon Eshkabilov
2023년 2월 3일
편집: Sulaymon Eshkabilov
2023년 2월 3일
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')
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
Sulaymon Eshkabilov
2023년 2월 3일
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;
Image Analyst
2023년 2월 3일
이동: Image Analyst
2023년 2월 3일
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)
% 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1283760/image.png)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!