How to interpolate a matrix

4 views (last 30 days)
Serena Solanki
Serena Solanki on 19 Feb 2018
Commented: Serena Solanki on 20 Feb 2018
Essentially I didn't know how to ask this as it probably is simple but I don't quite know what to do.
Essentially I want to create a response function for an earthquake record, where ultimately I want to plot the peak displacement against a varying time period. I am using the Runge-Kutta Method to integrate to get displacement from the acceleration data.
I have got a range of values for the time period -T0 and have calculated the state-space matrix A from this.
essentially I am unsure if i need to interpolate my A matrix to be the same size as my Npts in order for the loop to work.
Hope it makes sense and hope you can help!
Thanks in advance!!
for i=0.1:0.1:4; % Range of Time Periods defined
T0=(i);% seconds
w = (2*pi)/T0(1:end); %rad/s
w2=w(1:end)*w(1:end);
zita=0.05;
m=773; % Mass in MG
A1=[0 1
-w2(1:end) -(2*zita*w(1:end))]; %state-space matrix of coefficients
b=[0
1/m]; %state-space load vector
end
ft = m*acc.'; %acceleration data- converting to force f=ma
dt = 0.02; %seconds
NPTS = size(ft); %no.of points
tf = (NPTS-1)*dt;
t = 0:dt:tf;
A=A1(1:end);
dt_interp = 0.0001;
t_interp = dt_interp:dt_interp:tf;
ft_interp = F_interp(t, ft, t_interp);
NPTS_interp = size(t_interp,2);
yt = zeros(2,t_interp);
for i=1:(NPTS_interp-1)% Runge-Kutta loop, i = incremental time step
g1 = A(1:end)*yt(:,i)+b*ft_interp(i);
g2 = A(1:end)*(yt(:,i)+ 0.5*g1*dt_interp)+0.5*b*(ft_interp(i)+ft_interp(i+1));
g3 = A(1:end)*(yt(:,i)+ 0.5*g2*dt_interp)+0.5*b*(ft_interp(i)+ft_interp(i+1));
g4 = A(1:end)*(yt(:,i)+g3*dt_interp)+b*ft_interp(i+1);
ynew = yt(:,i)+(g1+2*g2+2*g3+g4)*dt_interp/6;
yt(:,i+1)=ynew; %storage
ut=yt(1,:); %displacement values
vt=yt(2,:);%velocity values
[pks,locs]=findpeaks(ut,t_interp);
Max_displacement=max(pks);
end
  5 Comments
Stephen23
Stephen23 on 20 Feb 2018
Edited: Stephen23 on 20 Feb 2018
"... interp1() and interp2() commands? .... These are both linear interpolators..."
Reading the interp1 and interp2 documentation shows that they support a lot more than just linear interpolation, including variations of splines and cubic interpolation. The documentation is available online for everyone to read.
"essentially I am unsure if i need to interpolate my A matrix to be the same size as my Npts in order for the loop to work."
Writing code by guessing is not very efficient. Even before you get to writing code down you should first understand the algorithm that you want to implement. Even write it out on paper, and work through a few iterations by hand: this will give you something to compare your code's output against (you do confirm that your code is giving reasonable output values, don't you?) and it allows you to understand the prerequisites and conditions for the algorithm to work.
"How to interpolate a matrix"
Read the iterp1 and interp2 documentation carefully. Try the examples. Try it with your data.
Serena Solanki
Serena Solanki on 20 Feb 2018
Hi Stephen
Thanks for the advice
I have tried doing this and have found a nested loop may be a better way forward rather than interpolating as it isn't what I actually needed.
Writing it out definitely helped!

Sign in to comment.

Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!