Taking data from matrix and using it in a function
4 views (last 30 days)
Show older comments
Let's denote
. I would like to find the maximum value of the function z, if I substitute
with -1 or 1. I created a
matrix of only -1 and 1 using de2bi function (I got 0's and 1's but substituted 0's with -1's). How can I "connect" the matrix with my function, so that I'll check all possible combinations and get the maximum value?



0 Comments
Answers (1)
Birdman
on 1 Apr 2020
Edited: Birdman
on 1 Apr 2020
As far as I understand, you want to change E1, E2, E3 and E4 respectively with combinations of -1 and 1. So the following code does that:
syms z(x,y) E1 E2 E3 E4
z(x,y)=(((sin(x).*(1+E1))./(3))+(1+E2))./(log10(y+E3)-E4);
A=perms([-1 1 -1 1]);
for i=1:size(A,1)
Z(x,y)=subs(z,{E1,E2,E3,E4},{A(i,1),A(i,2),A(i,3),A(i,4)})
end
After this point, you can proceed. If you have further question, we can discuss from here. Hope this gives the idea.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!