solving equation in matlab

9 次查看(过去 30 天)
Esraa El-Basha
Esraa El-Basha 2017-12-28
编辑: John BG 2018-1-4
I want to solve this equation in matlab to get the values of y knowing that
x =[0:0.1:7];
eq1 = ((x/7)^2*sqrt(abs(abs(x)-3)/(abs(x)-3))+(y/3)^2*sqrt(abs(y+3/7*sqrt(33))/(y+3/7*sqrt(33)))-1);
then draw x and y together.
  2 个评论
Walter Roberson
Walter Roberson 2017-12-28
is eq1 a constant? Is that constant 0 ? That is, is eq1 to be solved for the y that make eq1 0 when used with those x ?
Esraa El-Basha
Esraa El-Basha 2017-12-31
Yes, eq1 = 0 and i need to get all the values of y substituting by this range of x. and then draw x and y together.

请先登录,再进行评论。

回答(3 个)

Malhar Ashtaputre
Hello Esraa El-Basha,
Try to make the equation in following form.
y = function(eq1,x)
Then define x and eq1=0, then try running.

Walter Roberson
Walter Roberson 2018-1-2
syms x y
eq1 = ((x/7)^2*sqrt(abs(abs(x)-3)/(abs(x)-3))+(y/3)^2*sqrt(abs(y+3/7*sqrt(33))/(y+3/7*sqrt(33)))-1);
fimplicit(eq1, [-8 8 -3 3])
  1 个评论
John BG
John BG 2018-1-4
fimplicit returns a result that is all zeros except a single NaN
z=fimplicit(eq1, [-8 8 -3 3])
z.ZData
Then one realizes that it's a complex function, so solving complex functions requires to check both real and imaginary parts, or to work with abs.
Also, one wonders if the graph that fimplicit returns is of any use:

请先登录,再进行评论。


John BG
John BG 2018-1-4
编辑:John BG 2018-1-4
Hi Esraa
1. Check Real and Imaginary
Since the equation is complex, it's useful to check both real and imaginary parts of the equation:
clear all;clc;close all
x =[0:0.1:7];
y =[0:0.1:7];
[X Y]=meshgrid(x,y);
Z = ((X/7).^2*sqrt(abs(abs(X)-3)./(abs(X)-3))+(Y/3).^2*sqrt(abs(Y+3/7*sqrt(33))./(Y+3/7*sqrt(33)))-1);
figure(1);surf(X,Y,abs(Z));xlabel('X');ylabel('Y');
.
.
figure(2);surf(X,Y,imag(Z));xlabel('X');ylabel('Y');
.
.
the apparent minimum value is
min(min(Z))
ans =
22.835714285714282
for
x =[0:0.001:7];
y =[0:0.001:7];
..
min(min(Z))
=
2.332833357142857e+03
For abs(x)<3 the solution is complex
When x=>3 then the solution doesn't get any smaller than min(min(Z)) that seems to be 23.32
2. Asymptotic behavior apparently changes minimum
When changing x y ranges, such minimum value changes too
x =[-7:0.1:7];
y =[-7:0.1:7];
[X Y]=meshgrid(x,y);
Z = ((X/7).^2*sqrt(abs(abs(X)-3)./(abs(X)-3))+(Y/3).^2*sqrt(abs(Y+3/7*sqrt(33))./(Y+3/7*sqrt(33)))-1);
figure(1);surf(X,Y,abs(Z));xlabel('X');ylabel('Y');
figure(2);surf(X,Y,imag(Z));xlabel('X');ylabel('Y');
.
now
min(min(Z))
=
46.671428571428571
I tried smaller steps than 0.001, for the given range, which slowed down things.
Then when narrowing the range
x =[0:0.0001:.5];
y =[0:0.0001:.5];
..
min(min(Z))
=
-0.001044693333332 + 8.505952551020407i
3. Simplify
Stepping back on realizes that your the equation is the same, regarding zeros search, as
X^2*1./sqrt(abs(abs(X)-3))+
Y^2*1./(Y+3/7*sqrt(33)))-1)
these 2 terms will not zero for any both large values of X Y.
When approaching x=3 or y=-3/7*sqrt(33) the result rockets.
Now try this
x =[-5:0.01:5];
y =[-5:0.01:5];
[X Y]=meshgrid(x,y);
Z=X.^2*1./sqrt(abs(abs(X)-3))-Y.^2*1./(Y+3/7*sqrt(33))+1;
figure(1);surf(X,Y,10*log10(abs(Z)));xlabel('X');ylabel('Y');
.
that resembles the 'parenthesis like' curves obtained with fimplicit,
however, again increasing the range one realizes that the solutions are not a simple circle or ellipse but these two conic-like notch curves, plus the nearly flat notch running along X axis :
.
.
Therefore the solution to your equation are the zeros of
Z=X.^2*1./sqrt(abs(abs(X)-3))-Y.^2*1./(Y+3/7*sqrt(33))+1
Esraa
if you find this answer useful would you please be so kind to consider marking this answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance for time and attention
John BG

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by