How to use previous points calculated from a function.
4 次查看(过去 30 天)
显示 更早的评论
Hello I have the following function
d=abs(B32 + A32*[X;Y]);sqrt(A32(1,1)^2+A32(1,2)^2);
the answer (d) changes based on the row matlab is on.
I have no problem calculating (d) based on the row.
What I want to do is use an equation R = d2*(t2-t1)/(d1-d2)
What I want to do is d2 to equal the current (d) that is being calculated.
I want d1 to equal the previous answer for (d).
I want the first d1 that is used to = 0 then the next d1 to equal (d) and so forth.
Is this possible.
Any help is greatly appreciated.
2 个评论
Mitchell Thurston
2020-10-24
If I get the jist of what you're saying:
d1 = 0;
d2 = abs(B32 + A32*[X;Y]);
% it also looks like after the semicolon this is just being saved to "ans"
% .
% .
% .
% This is within some kind of loop
d2 = abs(B32 + A32*[X;Y]);
R = d2*(t2-t1)/(d1-d2);
d1 = d2;
Is this about what your asking for?
采纳的回答
更多回答(1 个)
KSSV
2020-10-24
You can solve the given equation:
R = d2*(t2-t1)/(d1-d2) ;
for d2 and solve it to get d2. We have d2 as:
d2 = R*d1/(R-t1+t2) ;
I assume that the (t2-t1) will be nothing but t(i+1)-t(i) .. if you use a loop; so this will be a time step and mostly will remain constant. Let it be dt. So the equation for d2 becomes:
d2 = R*d1/(R+dt)
Now you need not use a loop..get the distance d1 and then find d2.
d=abs(B32 + A32*[X;Y]);sqrt(A32(:,1).^2+A32(:,2).^2); %
The above formula should give you all d's at once. It might throw some error, in that case you need to give us more details about [X Y] and A32. Once d is obtained, use the equation for d2 and get d2.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!