How do I make x the subject of this function?

4 ビュー (過去 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 Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by