Looking for an iterative Solver to use in a loop with changing constants?
1 view (last 30 days)
Show older comments
I have not used any kind of iterative solver but I am facing a challenge when trying to resolve the following equation:
sigma = theta+acos((A+B+(2*A*B/(2*A*B/(A+B-(B-A)*cos(2*theta))-(A+B))))/(B-A))/2;
A & B are variables input by the user but do not vary during the loop. Sigma is changing during the loop though and I need to determine theta at each loop. Can anyone advise an iterative solver to resolve this and demonstrate briefly how it would be used in this application since I have not used it before.
Thanks, Adam
Answers (1)
Star Strider
on 23 Jul 2014
This would be my approach:
thta = @(theta,sigma,A,B) sigma - (theta+acos((A+B+(2*A*B/(2*A*B/(A+B-(B-A)*cos(2*theta))-(A+B))))/(B-A))/2);
A = 3;
B = 5;
sgma = 0:7;
for k1 = 1:length(sgma)
sigma = sgma(k1);
theta(k1) = fzero(@(theta) thta(theta,sigma,A,B),0);
end
The anonymous function thta is essentially your equation but subtracting it from sigma so it will have a root (zero) at theta. It will pick up A and B from the workspace and through the argument list, sigma will vary in the loop, and theta will be a vector containing one root (close to zero) for each set of arguments. If there are more than one root, you will need to provide initial estimates close to those roots.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!