taking too long to get a solution

4 views (last 30 days)
Ahsan Muhammad
Ahsan Muhammad on 27 Aug 2015
Answered: Ar K on 21 Jun 2022
Hi Everyone,
This code runs fine, i have defined values for everything except x and y. But it takes 4 - 5 hours. Is there a faster way to do this?
S=solve([C1*(A*x+B1*y^(1/N1))^-1 + C2*(A*x+B2*y^(1/N2))^-1 == 1, x/(y*N1)*(C1*(A*x+B1*y^(1/N1))^-1) + x/(y*N2)*(C2*(A*x+B2*y^(1/N2))^-1)==1],[x,y])

Answers (2)

Star Strider
Star Strider on 28 Aug 2015
Don’t use the Symbolic Math Toolbox. If you have the Optimization Toolbox, use the fsolve function:
[C1,A,B1,N1,C2,B2,N2] = deal(1,2,3,4,5,6,7); % Constants
% MAPPING: x = b(1), y = b(2)
Fn = @(b) [C1./(A*b(1)+B1*b(2).^(1/N1)) + C2./(A*b(1)+B2*b(2)^(1/N2)) - 1; b(1)./(b(2)*N1)*C1./(A*b(1)+B1*b(2).^(1/N1)) + b(1)./(b(2)*N2)*C2./(A*b(1)+B2*b(2)^(1/N2)) - 1];
B = fsolve(Fn, [1; 1]);
When I created values for the constants, it took fsolve about a second. Be sure to check the equations, since I recoded them to make them more efficient. I also substituted my ‘b’ vector for ‘x’ and ‘y’. See the documentation for fsolve for the coding of the function and other details.

Ar K
Ar K on 21 Jun 2022
Thanks a lot🙏

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!