MATLAB: How to obtain a no-loop iteration in MATLAB using anonymous functions

anonymous functioniterationno loops

I tried to adapt this base program to my needs, but I am running into an issue. In my particular program I have my function F dependent on other functions. Would you have suggestions on how to incorporate the same idea if the program was modified to include
q = sym('q',[1,10]);
i = 1:10;
M = @(q) tan(q)/(1+sin(7*q))
N = log(M(q))
F = i - 2*q*N == 0;
solq = solve(F,q)
I obtain the same errors in this program that I do in my actual program. I am informed that MATLAB is doing away with the sym('q',…) style argument in favor of 'syms q'. If I use this notation, everything ends up being symbolic, including the answer. I essentially want to solve the equation given in F. The general code works until I include an anonymous function. Is there a way around this?

Best Answer

It appears that the error here is related to how MATLAB is interpreting the multiplication and division used. Since your data is stored as vectors, you need to use "./" and ".*" in place of "/" and "*", if I correctly understand what you are trying to do.
The code below resolves this issue. Note, however, that "solve" returns a numerical solution:
q = sym('q',[1,10]);
i = sym(1:10);
M = tan(q)./(1+sin(7*q))
N = log(M)
F = i - 2*q.*N == 0;
solq = solve(F,q)
Note that solves 10 equations for 10 independent unknowns.
Best Regards,
Jim