Solve equation without symbolic math toolbox
显示 更早的评论
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
2 个评论
mylene
2025-12-20
编辑:Walter Roberson
2025-12-20
Move B to the right:
Square both sides: 

Let
: 

Multiply by
and rearrange: 

Walter Roberson
2025-12-20
This appears to be the same technique described at https://www.mathworks.com/matlabcentral/answers/122212-solve-equation-without-symbolic-math-toolbox#comment_3343869
采纳的回答
更多回答(2 个)
Sudesh
2025-10-28
编辑:Walter Roberson
2025-10-29
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.
mylene
2025-12-20
0 个投票
% Example data U = 1; Bx = [1.5; 2.0; 2.5]; % Column vector B = [1.1; 1.2; 1.3]; % Column vector
% Define quadratic coefficients: c2*a^2 + c1*a + c0 = 0 c2 = B.^2; c1 = -3 * U * Bx; c0 = 2 * U^2;
% Solving for r for each row r_results = zeros(length(B), 2); % Preallocate for two possible roots
for i = 1:length(B) % Find roots of the quadratic for a (which is r^3) a_roots = roots([c2(i), c1(i), c0(i)]);
% Convert back to r
r_results(i, :) = a_roots.^(1/3);
end类别
在 帮助中心 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!