Reputation: 605
Equation:
0 = x*114 - x*log3(x) - 20.28*y
I have Y = 10^3, 10^6, 10^9, 10^12, 10^15, ..... and above mentioned equation. How do I solve (i.e. getting values of x for different y) and plot this equation in MATLAB ?
Upvotes: 0
Views: 102
Reputation: 933
Assuming that the solution is unique, one way to solve the equation is numerically:
y = 10.^(3:3:15);
opts = optimset( 'TolFun', 1e-9, 'TolX', 1e-9, 'MaxIter', 1e6, 'MaxFunEvals', 1e6 );
for ii = 1 : length(y);
fcost = @(x)( x*114 - x*log10(x)/log10(3) - 20.28*y(ii) ).^2;
xopt(ii) = fminsearch( fcost, y(ii), opts );
fprintf( 1, 'y = %-5g : x = %-17.15g : f(xopt) = %-17.15g\n', ...
y(ii), xopt(ii), fcost(xopt(ii)) );
end
% Plot the answers on a log-log scale.
loglog( xopt, y, 'k*' );
The above produces the following output, so we can see that the solutions are valid.
y = 1000 : x = 185.637624348601 : f(xopt) = 6.37079420013969e-17
y = 1e+06 : x = 197078.905034998 : f(xopt) = 8.88178419700125e-16
y = 1e+09 : x = 210030727.535742 : f(xopt) = 5.82076609134674e-11
y = 1e+12 : x = 224814576366.276 : f(xopt) = 1.52587890625e-05
y = 1e+15 : x = 241850436303022 : f(xopt) = 0
There might be a better symbolic way to do it, but the above will work. I just guessed at the starting point for the search by setting it equal to y
. If you need more accuracy in the solution, look at help optimset
and help fminsearch
. There are arguments that you can pass in that control the accuracy of the solution and when the search will terminate.
Upvotes: 1