How to replace a value in function
Ältere Kommentare anzeigen
Hello, I automate the following function
f=@(x)0;
for i=1:3
h=@(x)x(i)^2
f=@(x) f(x) +h(x) % f= x(1)^2+x(2)^2+x(3)^2
end
The ISSUE IS:I want to replace x(3) =3 , so that the function would instead represent f=x(1)^2+x(2)^2+9. Is it possible?
Background information: My main goal is to to automatically create an abstract function (not necessarily the one mentioned above), replace it with known values of x and minimize it.
Any help whatsoever is hugely appreciated!
Thank you, Ela
Antworten (2)
Image Analyst
am 20 Jun. 2015
Abandon all that complicated nonsense, and simply do this:
x = 1 : 3;
f = sum(x.^2)
1 Kommentar
Elanorin Weaving
am 20 Jun. 2015
Azzi Abdelmalek
am 21 Jun. 2015
f=@(x) x^2
som=0
for k=1:3
som=som+f(k)
end
2 Kommentare
Elanorin Weaving
am 21 Jun. 2015
Azzi Abdelmalek
am 21 Jun. 2015
f=@(x) sum(x.^2)
f(1:3)
Kategorien
Mehr zu Image Arithmetic finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!