How to find the x value of a function given by points?

tinterval=[0:0.001:40]; %sec
acc=3;
w0=30;
Wspeed=acc*tinterval+w0;
tetae=Wspeed.*tinterval;
tetaeFract=rem(tetae,360);
I need to find the tinterval value when tetafract is equal to 60, and I need this as a value to use later in the script, I don't need it graphically.
Thank you in advance.

 Accepted Answer

Also, as you are working with floating point numbers, it would be better to compare using a tolerance.

4 Comments

Yes thank you I think is the way, indeed the value i need is 60 but in the array there is 60.009 how can i use the tolerance to find that index?
tinterval=[0:0.001:40]; %sec
acc=3;
w0=30;
Wspeed=acc*tinterval+w0;
tetae=Wspeed.*tinterval;
tetaeFract=rem(tetae,360);
%Define a tolerance
tol = 0.01;
idx = abs(tetaeFract - 60) < tol;
tetaeFract(idx)
ans = 1×4
59.9918 60.0058 60.0090 59.9960
new_values = tinterval(idx)
new_values = 1×4
1.7080 11.8820 24.7490 28.5410
Shouldn't 60.0058 be a better fit than 60.009?
yes perfect thank you very much!

Sign in to comment.

More Answers (0)

Products

Release

R2023b

Community Treasure Hunt

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

Start Hunting!