Go to Post A better way would be better..... - WizardOfAz [more]
Home
Go Back   Chief Delphi > Other > Math and Science
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 07-10-2013, 20:55
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,042
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: calculating position using follower wheels

Quote:
Originally Posted by flameout View Post
If I really cared about accuracy and speed, I would be using Simpson's Rule integration...
It's a cost/benefit thing. The cost of converting Euler to trapezoidal for this problem is very small. Going from trap to Simpson's would require more rework, make the code less readable, and probably even slow it down for equivalent accuracy.

Quote:
Another good technique would be to use an ODE solver rather than pure integration -- if I were to do this, I'd probably use MATLAB's built in 4th/5th order adaptive Runge-Kutta solver (ode45). This would probably be plenty fast as well.
It would be interesting to do a comparison. My guess is that for this problem, trapezoidal in compiled C would be just as fast for equivalent accuracy as RK in MatLab.


Reply With Quote
  #2   Spotlight this post!  
Unread 07-10-2013, 21:07
flameout flameout is offline
AKA Ryan Van Why
FRC #0957 (SWARM)
Team Role: Alumni
 
Join Date: Sep 2009
Rookie Year: 2009
Location: Oregon
Posts: 168
flameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to all
Re: calculating position using follower wheels

Quote:
Originally Posted by Ether View Post
It's a cost/benefit thing. The cost of converting Euler to trapezoidal for this problem is very small. Going from trap to Simpson's would require more rework, make the code less readable, and probably even slow it down for equivalent accuracy.
True (except for the last part -- I don't think Simpson's integration would slow it down for equivalent accuracy, but I haven't tried it, so I don't know).

Quote:
It would be interesting to do a comparison. My guess is that for this problem, trapezoidal in compiled C would be just as fast for equivalent accuracy as RK in MatLab
Having used MATLAB a bit, I think compiled C++ w/ trapezoidal integration would be way faster for the same accuracy than MATLAB code using an RK-based solver.

Here's code that solves it using one of MATLAB's adaptive ODE solvers (4/5th-order Runge-Kutta (I don't recall which formulation it is)):
Spoiler for more code:
Code:
% Set up various useful functions that don't require integration to calculate
angle = @(t) 5*pi/12 - 3.75 + 3.75 * cos(t/2.5); % Obtained analytically (by hand)
forward = @(t) 5*sin(t/2);
strafe_right = @(t) 4*sin(t/2.2);
xvel = @(t) cos(angle(t)) * forward(t) + cos(angle(t) - pi/2) * strafe_right(t);
yvel = @(t) sin(angle(t)) * forward(t) + sin(angle(t) - pi/2) * strafe_right(t);
spd  = @(t) sqrt(forward(t)^2 + strafe_right(t)^2);

% Set up for the ODE solution
tspan = [0 30];
x0    = [0; 0; 0]; % xpos, ypos, distance

% The ODE function
dynamics = @(t,x) [xvel(t); yvel(t); spd(t)];

% Call ode45
diffsoln = ode45(dynamics, tspan, x0);

% Function for obtaining the state at a given time (for plotting)
statefun = @(t) deval(diffsoln, t);

% Time values for plot (using a lot of points so it looks good).
times = linspace(tspan(1), tspan(2), 10000);

% X and Y positions
xpos = [1 0 0] * statefun(times);
ypos = [0 1 0] * statefun(times);

% Do the plotting
plot(xpos, ypos, 'LineWidth', 5)
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 06:44.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi