Contents

function [peakVals,mainComputationTime,nVals,aVals]=paramSweepParallel(nNum,aNum,hTopAxes)

Parameter Sweep of ODEs

This is a parameter sweep study of a 2nd order ODE system.

$m\ddot{x} + b\dot{x} + kx = 0$

We solve the ODE for a time span of 0 to 25 seconds, with initial conditions $x(0) = 0$ and $\dot{x}(0) = 1$. We sweep the parameters $b$ and $k$ and record the peak values of $x$ for each condition. At the end, we plot a surface of the results.

% SCd
if ~nargin
    nNum = 5;
    aNum = 5;
    hTopAxes = gca;
end

Initialize Problem

nVals = round(linspace(10, 20, nNum));  % number of segments
aVals = linspace(1, 200, aNum);  % cross sectional area
[nGrid, aGrid] = meshgrid(nVals, aVals);
peakVals = nan(size(aGrid));

Parameter Sweep

t0 = tic;
parfor ii = 1:numel(aGrid)
    % Solve ODE
    Y=trussCantilever(nGrid(ii),aGrid(ii));

    % Determine peak deflection in Y direction
    peakVals(ii) = max(Y(:,2));
end
mainComputationTime = toc(t0);
Starting parallel pool (parpool) using the 'local' profile ... connected to 4 workers.

Visualize

if ~isempty(hTopAxes)
    visualizeParamSweep(hTopAxes,nVals, aVals, peakVals);
end
ans =
   1.0e-03 *
    0.0731    0.0342    0.0179    0.0195    0.0187
    0.2926    0.1737    0.1244    0.0790    0.0602
    0.2897    0.1861    0.1397    0.0948    0.0735
    0.2555    0.1783    0.1391    0.0956    0.0768
    0.2257    0.1634    0.1322    0.0952    0.0758