MATLAB Answers

Solve equation for one unknown with one known parameter

6 views (last 30 days)
clear all
clc
a=0.5
x=linspace(-2*a,2*a,100)
eqn=@(x,y,a)(1/2*a^2)*[x^2./(2-(1-(x./(2*a))^2-(y./(2*a))^2)+sqrt((1-(x./(2*a))^2-(y./(2*a))^2)+(y./a)^2))-y^2./((1-(x./(2*a))^2-(y./(2*a))^2)+sqrt((1-(x./(2*a))^2-(y./(2*a))^2)+(y./a)^2))]-1==0;
solve(eqn,y)
Answer is
Unrecognized function or variable 'y'.
Error in naca (line 6)
solve(eqn,y)
how can I solve y for x matrix value
  2 Comments
Star Strider
Star Strider on 18 May 2021
The actual equations are:
I = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/621828/image.png');
figure
imshow(I)
.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 18 May 2021
Try something like this —
a=0.5;
% x=linspace(-2*a,2*a,100)
x=linspace(-2*a,2*a,20);
eqn=@(x,y,a)(1/2*a^2)*[x^2./(2-(1-(x./(2*a))^2-(y./(2*a))^2)+sqrt((1-(x./(2*a))^2-(y./(2*a))^2)+(y./a)^2))-y^2./((1-(x./(2*a))^2-(y./(2*a))^2)+sqrt((1-(x./(2*a))^2-(y./(2*a))^2)+(y./a)^2))]-1;
for k = 1:numel(x)
yv(k,:) = fsolve(@(y)eqn(x(k),y,a), 10);
end
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
Results = table(x', yv)
Results = 20×2 table
Var1 yv _________ ______ -1 1.9833 -0.89474 2.1056 -0.78947 2.2028 -0.68421 2.2812 -0.57895 2.3444 -0.47368 2.3946 -0.36842 2.4335 -0.26316 2.4619 -0.15789 2.4805 -0.052632 2.4897 0.052632 2.4897 0.15789 2.4805 0.26316 2.4619 0.36842 2.4335 0.47368 2.3946 0.57895 2.3444
It might be necessary to use the uniquetol function to eliminate duplicate (or near-duplicate) values of ‘yv’ and thier associated ‘x’ values.
.
  9 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by