Finding a value with interp1 without having xq

5 views (last 30 days)

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
dpb
dpb on 18 Nov 2015
"in line 74 it should be: for j=i:-1:1"
Making that change results in (I named the script something much shorter that can recognize) and rearranged slightly to get rid of the excessively long lines early on so the for loop actually begins at L72 here as also removed the "destroying of everything else" clear at the beginning --
>> rosana
Error using griddedInterpolant
The grid vectors do not define a grid of points that match the given values.
Error in interp1>Interp1D (line 346)
F = griddedInterpolant(Xext,V,method);
Error in interp1 (line 241)
Vq = Interp1D(X,V,Xq,method);
Error in rosana (line 77)
phit_tn=interp1(tao,y(1,1:i),taoq);
>>
Again I'd plead-- DESCRIBE the details of the solution looked for in more detail regarding what to do with the time values over which this "interpolation" is being done in the k*dt term. Is it varying, too, along with the phi(t) term????
Rosana Reyes
Rosana Reyes on 19 Nov 2015
I am really sorry, I really don't understand your question about what is the desired solution (I am pretty new to matlab and this matlab answers forum), but I'll try to answer on what I understand:
I have uploaded 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,:) it is pretty much a sinusoidal function.
So for every t and its corresponding phi I want to find a previous t (I will call it t-tn) and its corresponding phi that will satisfy this equation:
phi(t)-phi(t-tn)+wo*(t-(t-tn))= 2*pi/N
When I obtain the satisfying values then I will compute the two t's to get the value of tn (delay time) and then use it for a further calculation.
tn=t-(t-tn)
If my step time was small enough maybe I could find the values that satisfy my equation in my own historical values of phi and t but of course this would make my code very slow and not effective (I guess). That's why I think I need to interpolate.
Thanks again for your help!

Sign in to comment.

Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!