How do I make x the subject of this function?

조회 수: 2 (최근 30일)
Zaraleena
Zaraleena 2024년 9월 6일
댓글: Zaraleena 2024년 9월 6일
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

답변 (2개)

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

댓글을 달려면 로그인하십시오.


Torsten
Torsten 2024년 9월 6일
편집: Torsten 2024년 9월 6일
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
Walter Roberson
Walter Roberson 2024년 9월 6일
Note that f(X) is never zero. The equation never reaches 0.2170535 with that D value.
Zaraleena
Zaraleena 2024년 9월 6일
@Walter Roberson @Piyush Kumar Thank you so much for the help.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by