Finding a value with interp1 without having xq
I am running a model for drilling bit rock interaction and for it I have to find a value of time t1 that is related to a value of angular displacement phi(t1) in the following way:
2*pi/n= phi(t2)- phi(t1) + k*(t2-t1)..................k and n are constants.
I have the current values of phi(t2) and t2 and a list of historical values for t and phi so I need to find the corresponding values of t1 and phi(t1) that will satisfy the equation. Since those values are not going to be exactly the ones I have in my phi(t) function I am thinking about interpolation but since I don't have the value of t1 to input in the interp1 function I really don't know the best way to do it.
I have uploaded the code here. As you can see my problem is with the calculations in lines 73-88. Here is what I have tried to do (but I am pretty sure It is not the proper way):
1. First I try to look for tao1 and phi(tao1) in my given set of values under tao2 and phi(tao2) and check for the satisfaction of the equation. In the beginning it is always <2*pi/n.
2. When it finds the next tao1 and phi(tao1) that make it to be greater than 2*pi/n I take those two pairs of values( tao(j), phi(j) & tao(j+1), phi(j+1)) and try to interpolate between them to find the exact pair that will satisfy my equation.
3. I define a new matrix taoq with a 500 values between tao(j) and tao(j+1) and interpolate to get a matrix of phi values for each new tao
taoq=tao(j):(tao(j+1)-tao(j))/500:tao(j+1); phit_tn=interp1(tao,y(1,1:i),taoq);
4. Then I check for each new pair of values and my original tao2,phi(tao2) to see if the equation is satisfied. (lines 81-86)
If I run the code as it is, I star getting NaN after the second iteration.
Any suggestions?
*EDIT: I just realized that in line 74 it should be: for j=i:-1:1 so the loop can go in descending order.*
*EDIT2: I have uploaded in the comments a code without this interpolation so you can see how is the normal behavior of the function phi(tao) (that is the same as y(1,:)*
4 Comments
Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!