function approximation using any optimization routine

I've two linear equs: x1+x2=10 & x1-x2=2;
I would like to solve these using any optimization method for which these have to convert into a single function; In excel:i am doing this by excel solver by minimising sum sq deviation (initially assuming any values for x1 & x2); pl. help how to do it in matlab! Ex: I try to apply ga; but fail to make the needed fitness function!

 采纳的回答

fun = @(x) (x(1)+x(2)-10).^2 + (x(1)-x(2)-2).^2

5 个评论

Thanks; I had mistaken by taken -ve sign instead +ve in bet. the two equations!
The general form is ((lhs) - (rhs)).^2 where lhs is left hand side and rhs is right hand side; you calculate that for each equation and then add them together.
Instead of writing equations::if I make A&b matrix data, how to call these(say):
fun=@(x)(sum(A*x-b).^2);
I guess have to use loop for indexing A,b&x? if i get some guidance!
In one of your answer I got a similar type:
@(x)A*x.'-b % x.' ?
res = @(x)sum(fun(x).^2);
X = fmincon(res,x0);
Yes, looks good. You might find you need @(x)A*x-b instead of @(x)A*x.'-b but one of the two should work.
Thanks! when using fsolve
fun=@(x)A*x-b % is ok
but ga works as
fun=@(x)sum (A*x'-b).^2
Maths is really an obsession; I am 50+ but pass my lots of time in maths; these days R is also equally informative! I've seen vdo in matlab site where even 70+ resource personalities also giving demos/taking classes::it might be challenging to keep a pace with all topics of maths! For ex: I donot like fuzzy&markov! thanks once again!

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by