I am trying to add terms to an anonymous function in a for loop.
Isotherm = @(N) log(N)-log(P);
k=0;
for an=a
Isotherm2 = @(N) (1/T)*an*mpower(N,k);
Isotherm = @(N) Isotherm(N) + Isotherm2(N);
k=k+1;
end
k=0;
for bn=b
Isotherm2 = @(N) bn*mpower(N,k);
Isotherm = @(N) Isotherm(N) + Isotherm2(N);
k=k+1;
end
I’ve tried the preceding code, but it is not working correctly. Do I need to use an m-file function?
It’s a little hard to follow what you are intending to do. However, if
Nis a scalar value, the following vectorized solution should perform the computation you want:Incidentally, as much as I DID NOT expect the following to work, it actually does:
So the way you are adding your anonymous functions may not be the source of your problem, although it is a very confusing way to do things and may have some other limitations I have yet to find.