Borrar filtros
Borrar filtros

How do I make x the subject of this function?

57 visualizaciones (últimos 30 días)
Zaraleena Adamson
Zaraleena Adamson el 6 de Sept. de 2024 a las 15:23
Comentada: Zaraleena Adamson el 6 de Sept. de 2024 a las 22:19
What code do I use MATLAB to make x the subject in the function below?
Y = [D^2 * acos(1-(2x/D)]- [squareroot(x(D-x) * (D-2x)] / [pi*(D^2)]
Where D=0.05m
x=unknown
y=0.2170535

Respuestas (2)

Piyush Kumar
Piyush Kumar el 6 de Sept. de 2024 a las 17:35
You can use symbolic variables and solve function.
I found this example on the same page -
syms a b c x
b = 2;
c = 3;
x = 3;
eqn = a*x^2 + b*x + c == 0
eqn = 
S = solve(eqn, a)
S = 
I tried for your case, but it is unable to find explicit solution -
syms x D y
% D = 0.1;
% y = 0.2;
% Define the function
Y = (D^2 * acos(1 - (2*x/D))) - (sqrt(x * (D - x) * (D - 2*x)) / (pi * (D^2)));
% Solve for x
solution = solve(Y == y, x);
Warning: Unable to find explicit solution. For options, see help.
% Display the solution
disp(solution);
  2 comentarios
Piyush Kumar
Piyush Kumar el 6 de Sept. de 2024 a las 17:45
I also tried with fzero to find the roots of the function -
D = 0.05;
y = 0.2170535;
% Define the function
f = @(x) (D^2 * acos(1 - (2*x/D))) - (sqrt(x * (D - x) * (D - 2*x)) / (pi * (D^2))) - y;
% Find a root near an initial guess
initial_guess = D / 2;
solution = fzero(f, initial_guess);
Exiting fzero: aborting search for an interval containing a sign change because complex function value encountered during search. (Function value at 0.0257071 is -0.21306-0.11966i.) Check function or try again with a different starting value.
disp(solution);
NaN
Torsten
Torsten el 6 de Sept. de 2024 a las 17:58
A plot of the function for 0 <= x <= D/2 says more than a thousand solves ...

Iniciar sesión para comentar.


Torsten
Torsten el 6 de Sept. de 2024 a las 17:37
Editada: Torsten el 6 de Sept. de 2024 a las 17:59
D = 0.05;
Y = 0.2170535;
f = @(X) Y - (D^2 * acos(1-(2*X/D)) - sqrt(X.*(D-X) .* (D-2*X)) / (pi*D^2));
X = 0:0.001:0.025;
plot(X,f(X))
  2 comentarios
Walter Roberson
Walter Roberson el 6 de Sept. de 2024 a las 21:00
Note that f(X) is never zero. The equation never reaches 0.2170535 with that D value.
Zaraleena Adamson
Zaraleena Adamson el 6 de Sept. de 2024 a las 22:19
@Walter Roberson @Piyush Kumar Thank you so much for the help.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by