How do I make x the subject of this function?

57 次查看(过去 30 天)
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,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 个评论
Piyush Kumar
Piyush Kumar 2024-9-6,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 2024-9-6,17:58
A plot of the function for 0 <= x <= D/2 says more than a thousand solves ...

请先登录,再进行评论。


Torsten
Torsten 2024-9-6,17:37
编辑:Torsten 2024-9-6,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))

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by