In the previous example, we have learnt how to
calculate a singlevariate model using a taylor series method when no
knowledge about form of relation is known between input and output. This
example will extend the same using iterative application of
singlevariate model fitting.

We will consider a bivariate model and same can be easily generalized for higher dimensions.

**Problem Statement:**We consider a system where there are two inputs/parameters (x and y) which we can change and observe the output (z). Our aim is to find a relation between this output and inputs but again we don't know what relation form(whether it is exponential, logarithmic, linear or trigonometric) exists.

**Taylor Series Method**see this article for Taylor Series Method http://matlabbyexamples.blogspot.com/2011/12/singlevariate-model-fitting-for.html.

**Iterative Taylor Series Method**We will first make one parameter (y) constant (let us say at y0) and change the other one (x) only. Then we try to fit a taylor series model in to it and we get coefficient b_n|at y=y0 such that \[ f(x) = \sum_n{b_n x^n} \].

Now we will change the parameter y to y1 and do the same fit again to get a different set of coefficients b_n|at y=y1. Do it for all value of y and each time you get a 1xN vector b containing b_n's. Now stack them such that we get a matrix B each row represent b for one value of y. Now observe that ith column (let us call it B_i) represents b_i's for all values of y.

Now it is clear that these columns are only dependent on value of y. So again we can fit a taylor series to each of these columns such that \[ b_n = \sum_m{c_m y^m} \]. This can be done by solving \[B_n = Y*C\]

So we have the final model as

\[ f(x) = \sum_n{\sum_m{c_{m,n} y^m} x^n} \].

**MATLAB Implementation:**where taylorseriesfit1D is given asfunction C=taylorseriesfit2D(X,Y,Z);

%assumes X and Y are meshgrid format matrix

for i=1:length(y)

z=Z(i,:)';

B(i,:)=taylorseriesfit1D(X(1,:),z);

end

for i=1:size(B,2)

C(:,i)=taylorseriesfit1D(Y(:,1),B(:,i));

end

function B= taylorseriesfit1D(x,z)

Xmat=[ones(size(x)) x x.^2 x.^3 x.^4 x.^5 x.^6 x.^7];

B=Xmat\z;

**Simulation Data generation:**C will come like for N=7.x=[0:0.1:1]';

y=[0:.1:pi/2]';

[X Y ]=meshgrid(x,y);

Z=exp(X).*exp(Y);

C=taylorseriesfit2D(X,Y,Z)

1.0000 1.0000 0.5000 0.1667 0.0416 0.0085 0.0012 0.0003

1.0000 1.0000 0.5000 0.1667 0.0416 0.0085 0.0012 0.0003

0.5000 0.5000 0.2500 0.0833 0.0208 0.0043 0.0006 0.0002

0.1669 0.1669 0.0835 0.0278 0.0069 0.0014 0.0002 0.0001

0.0410 0.0410 0.0205 0.0068 0.0017 0.0004 0.0000 0.0000

0.0092 0.0092 0.0046 0.0015 0.0004 0.0001 0.0000 0.0000

0.0008 0.0008 0.0004 0.0001 0.0000 0.0000 0.0000 0.0000

0.0004 0.0004 0.0002 0.0001 0.0000 0.0000 0.0000 0.0000

**Final Guesses**Again we can guess the model by observing these coefficients and plotting them with respect to m,n (Fig1). First thing we can observer that it is symmetric, therefor exihibit the same relations for both the inputs to ouput.

Fig1: Plot C vrs m,n |

Again, we cannot guess, even then these matrixes are sufficient for all numerical purposes.

## No comments:

## Post a Comment