‘What is difference between these two expressions?’
The way they are implemented in MATLAB. The documentation for mldivide,\ explains how it works (so I won’t go into that here), and the reason it is more stable and preferred over taking the inverse and multiplying.
Use an anonymous function to create your‘y’ function, then use thenorm function to create your cost function, then thefminsearch function to do the ‘minimize’ step. See the section on ‘Anonymous Functions’ inFunction Basics for details.
If you want to write a fitting function for:
y = m*x + b
you would write it as:
yfun = @(b,x) b(1).*x + b(2);
That should give you a hint on how to go about this.
Best Answer