Solve equation without symbolic math toolbox
    180 views (last 30 days)
  
       Show older comments
    
Hello ,
I'm trying to solve this equation : 
0 = (U/r.^3)* sqrt(-2+((3*r.^3)*(Bx/U)))-B
U is a constant
Bx and B are column matrix
I would have as a result a value of r for each value of Bx and B
is it possible to do this without the Symbolic math toolbox ?
Thank you
0 Comments
Accepted Answer
  Chris C
      
 on 19 Mar 2014
        You can run this with two functions. The first function I have designated as myMain.m and it is written as..
r0 = rand(3,3);
fsolve(@myfun,r0)
The second function myfun.m is called by the first function by passing initial guesses of r as r0. I altered the way your equation above was written and wrote the function as...
function F = myfun(r)
Bx = rand(3,1);
B = rand(3,1);
U = rand(1);
F = (U)*sqrt(-2+((3*r.^3)*(Bx/U)))-r.^3*B;
end
Change the matrices to whatever numbers you need and it should work.
Good luck.
3 Comments
  David Goodmanson
      
      
 about 2 hours ago
				Am I missing something here?  It looks like the OP from awhile ago now was looking for the solution of
(U/r^3)*sqrt(-2 + 3*r^3*Bx/U) - B = 0
for pairs (Bx, B).  Since r only comes in as r^3, set r^3 = a.  Square both sides and rearrange to obtain
-2 + 3*a*Bx/U - (B/U)^2*a^2 = 0
Solve this with
a = roots([-(B/U)^2  3*(Bx/U) - 2])
then
 r = a^(1/3).
Since the equation was squared, you have to go back and determine which of the two roots satisfy the original equation and discard the other one.  In exchange for that step there is no guessing around with a solver for what size the numerical solution might be.
Presumably if a is real then the real solution for r is the one that is wanted.  If a is complex, then that is the way it is.
More Answers (1)
  Sudesh
 about 22 hours ago
        
      Edited: Walter Roberson
      
      
 about 2 hours ago
  
      can solve this numerically without the Symbolic Math Toolbox. Since you want a value of rrr for each pair of BxBxBx and BBB, you can use numerical root-finding methods like fzero in MATLAB. Here’s a step-by-step guide: 
Your equation is:
You want to solve for rrr, given UUU, BxBxBx (a column vector), and BBB (a column vector of the same size).
MATLAB Approach: 
U = 1; % Example value
Bx = [0.5; 1.2; 0.8]; % Example column vector
B = [0.1; 0.2; 0.15]; % Example column vector
r_values = zeros(size(Bx)); % Preallocate
for k = 1:length(Bx)
    func = @(r) (U./r.^3).*sqrt(-2 + (3*r.^3)*(Bx(k)/U)) - B(k);
    % Provide an initial guess for r, say 0.5
    r_guess = 0.5;
    % Solve numerically
    r_values(k) = fzero(func, r_guess);
end
disp(r_values)
Notes:
- Initial guess: fzero requires a starting point. You might need to adjust it depending on the expected range of r.
- Vectorization: Each r depends on a pair (Bx(k), B(k)), so a for loop is appropriate.
0 Comments
See Also
Categories
				Find more on Symbolic Math Toolbox in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


