[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Recursion
From: |
Thomas D. Dean |
Subject: |
Re: Recursion |
Date: |
Mon, 6 Mar 2017 19:24:07 -0800 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 |
On 03/06/2017 07:06 PM, Thomas D. Dean wrote:
I have an application that is called with two points and returns the
distance between the points and a mid point. One example returns a
distance of 5474. My function is not linear. But, a more simple
example illustrates my problem.
Here is a better example, which produces the output I want to save. The
printf(...) statement displays the data I want to keep, in the order I
want it.
function [dist, mid] = gcr(p1,p2)
p3 = p2 - p1;
dist = sqrt(p3*p3');
mid = (p1 + p2) ./ 2;
if dist < 300
printf("[%.1f %.1f] [%.1f %.1f] %.1f [%.1f %.1f]\n",p1,p2,dist,mid)
endif;
if dist > 300
savemid = mid;
[dist, mid] = gcr(p1, mid);
[dist, mid] = gcr(savemid, p2);
endif;
endfunction;
P1=[1000,2000]
P2=[8000,9000]
[distance, midpoint] = gcr(P1,P2)
Tomj Dean
- Recursion, Thomas D. Dean, 2017/03/06
- Re: Recursion,
Thomas D. Dean <=