Reverse modelling - function fitting to dataset
4 views (last 30 days)
Show older comments
Hi!
I have a question, I would like to make a simulation model through reverse modelling. I have a data set to fit the simulation model. I tried to write a piece of code to practise, but I dont know how to make it work. What I want to do is making some kind of code (already got it) with for example three unknown parameters. These three parameters should be 'fit' within a range so that the mean squared error is as close to 0 as possible. I guess I need a function where after I try to find the combination of parameters which will result in mean squared error of around 0.
I don't need someone to do my homework, but I like to know were to start and what I need to google.
This is what I got so far:
function [m] = stat(a,b,c,d)
e = sin(a);
f = cos(b);
g = tan(c);
h = e*f;
i = g+e;
s = h-i;
m = sum(sqrt((s-d).^2));
end
and the code:
dataset = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21];
dataset = sin(dataset);
%plot(meetdata)
for p1 = 0 : 1 : 21
for p2 = 0.0 :0.1:2.0
for p3 = 0.01 :0.01: 0.4
[answer] = stat(p1,p2,p3,dataset);
disp(answer)
end
end
end
p1 = 0 : 1 : 21;
p2 = 0.0 :0.1:2.0;
p3 = 0.01 :0.01: 0.4;
fit = fminsearch(stat,0);
disp(fit)
Thank you!
1 Comment
Star Strider
on 11 May 2016
You seem to want to do ‘system identification’. This takes input to and output data from a system and (usually assuming a linear time-invariant system), identifies a system that could produce the desired output from a given input. See the documentation for the System Identification Toolbox for details. If you have the Signal Processing Toolbox, consider using the invfreqz function.
Your desire to get ‘a mean squared error of around 0’ is laudable but completely unrealistic in most real-world situations.
Answers (0)
See Also
Categories
Find more on Biomedical Imaging in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!