Solve equation without symbolic math toolbox
132 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Benoit
le 19 Mar 2014
Commenté : Walter Roberson
le 6 Nov 2025 à 18:22
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 commentaires
Réponse acceptée
Chris C
le 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 commentaires
David Goodmanson
le 29 Oct 2025 à 6:13
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.
Plus de réponses (2)
Sudesh
le 28 Oct 2025 à 9:24
Modifié(e) : Walter Roberson
le 29 Oct 2025 à 6:16
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 commentaires
Preetham
le 6 Nov 2025 à 6:03
1ans: 0 = (U/r.^3)* sqrt(-2+((3*r.^3)*(Bx/U)))-B
1 commentaire
Walter Roberson
le 6 Nov 2025 à 18:22
I do not understand how this solves the question that was asked? It is not even valid MATLAB syntax.
syms U r Bx B
0 = (U/r.^3)* sqrt(-2+((3*r.^3)*(Bx/U)))-B
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!