Filter löschen
Filter löschen

How do I make x the subject of this function?

8 Ansichten (letzte 30 Tage)
Zaraleena Adamson
Zaraleena Adamson am 6 Sep. 2024
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

Antworten (2)

Piyush Kumar
Piyush Kumar am 6 Sep. 2024
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 Kommentare
Piyush Kumar
Piyush Kumar am 6 Sep. 2024
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 am 6 Sep. 2024
A plot of the function for 0 <= x <= D/2 says more than a thousand solves ...

Melden Sie sich an, um zu kommentieren.


Torsten
Torsten am 6 Sep. 2024
Bearbeitet: Torsten am 6 Sep. 2024
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 Kommentare
Walter Roberson
Walter Roberson am 6 Sep. 2024
Note that f(X) is never zero. The equation never reaches 0.2170535 with that D value.
Zaraleena Adamson
Zaraleena Adamson am 6 Sep. 2024
@Walter Roberson @Piyush Kumar Thank you so much for the help.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by