How to create a linearly interpolated symbolic function from data?

9 views (last 30 days)
I have measurements that can be described with unknown (and probably complicated) functions. I need symbolic functions that return the linear interpolated numbers between any two measurement points for any given time so I can define the Laplace-transforms of these functions. How can this be done?
  2 Comments
Tibor Guba
Tibor Guba on 5 Apr 2016
Edited: Tibor Guba on 5 Apr 2016
Here is the working example of the program in Mathcad. The red dots are measured, the blue line is symbolic. For the Laplace transform I have to use the function represented by the blue line, but its explicit formula is unknown and irrelevant. It is enough to have the linear interpolated values between the red dots. My goal is to obtain this symbolic function.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 4 Apr 2016
Let x be the timepoints and y be the associated data values. Then for any time t between x(J) and x(J+1)
heaviside(t - x(J)) * heaviside(x(J+1) - t) * (y(J) + (t-x(J))/(x(J+1)-x(J)) * (y(J+1)-y(J))
so sum those formula over J = 1 to length(x)-1
I might have messed up the code slightly, as I simply wrote it out. It is the standard "origin plus a ratio of the change in value" calculation, together with a pair of heaviside that will only multiply to non-zero when the value is within the range.
Caution: you need to adjust this to take into account the value associated with heaviside(0), which there is no standard value for. Sometimes you want heaviside(0) to be 0, sometimes you want it to be 1, and it is not uncommon to see it defined as 1/2 . If it is defined as 0, then you need to use a dirac delta to add in the value at every boundary. If it is 1/2 then you need to use a dirac delta to add in half of the value at each boundary.
If you have R2015a or later see sympref() for adjusting the value of heaviside at 0.
  2 Comments
Tibor Guba
Tibor Guba on 5 Apr 2016
I checked the code out. The only issue with the syntax in the beginning was, that it lacked a parenthesis. I rewrote it to my variable names and attached everything for you to try out:
DATA = csvread('l1=1.0mm_l2=2.7mm SIMA.csv');
%everything in millimetres
l1 = 1; l2=2.7; V0 = 150000; r = 45;
A = pi*r^2;
Skala = 1e6 * A * l2 / V0; % scaling from ppm to number
tm = DATA(:,1); % time measured
qm = DATA(:,2) / Skala; % quantity measured
kar = 0.006;
w0 = 0; w1=0.02;
% N=101;
M = length(qm);
% dw = (w1 - w0) / N;
w = linspace(w0,w1,N);
pm = kar + 1i*w;
%sympref();
syms t s;
syms interpolalt(t);
J = linspace (1, M-1, M-1)';
interpolalt (t) = heaviside( t - tm(J) ) * heaviside(tm(J+1) - t) * ( qm(J) + ( t - tm(J) ) * (qm (J+1) - qm(J) ) / ( tm(J+1) - tm(J) ) );
I see, how your line works, but I am not sure how to do the summing symbolically. Could you please help me with it?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!