Search code examples
matlabsimulink

Finding the z for z=f(x,y) in simulink


I have a Data table that can be imported into '2d-lookup table' of simulink. The rows and columns are not equally spaced. How do i create a model which takes x,y as inputs and gives z as output just by interpolating from the table. (i.e. for x,y which are some values that are between the values in table, it should generate polynomial equation based on table values and take the inputs and give the result ).

I can get it using matlab curvefit app, but i am restricted to use simulink.


Solution

  • You already almost did what you want. Using Simulink 2-D lookup table let you interpolate data automatically: First example Look at this: I set not equally spaced data and this works fine! Table Data is your z function values. So just change x,y (in my example it's u1,u2) and you will get what you want. You can see it works for (x,y) = [2 8].

    Now, lets solve second problem - how to take sum of all z values? Important moment here - what sum you want to get! You know, Simulink has a lot of different solvers with variable or fixed step. So, solving it with fixed step, for example, dt = 0.2 will give you all answers for t= 0, 0.2, 0.4, ... and so on. It will interpolate you entering data and solve z for each and if you get sum here would it be what you want? If yes, easiest way - is to use Integrator block. Something like this: enter image description here

    But! What if you want to solve this only for values, you set in your x,y in workspace ( (1 1), (3 8) , (7 10) pairs from your comment) and whats to get sum of 3 zs only? It;s a good another question, maybe it's harder than using 2d lookup tables :)

    I will show one of many possible solutions: go to Configuration Parameters/Solver and set fixed step with step size = 1. And use this: enter image description here

    you can see it shows you 101 but it must be 95 in your case (1+24+70)! It's due to the fact simulink solves it for t = (0, 0) too! Interpolating data for t=0 give additional 6. It solves easily - add in your z table values for x,y = 0.

    Hope it's clear now!