Solved

Can someone please see why I am getting this error?

Posted on 2009-03-30
3
971 Views
Last Modified: 2016-02-10
I am new to Matlab and I am getting the following error;
Warning: Imaginary parts of complex X and/or Y arguments ignored
> In create_hyperbola at 13
Warning: Imaginary parts of complex X and/or Y arguments ignored
> In create_hyperbola at 15

what does this mean and why is this?

thanks in advance
% Program to plot the hyperbola

% y^2/a^2 - x^2/b^2 = 1

% The hyperbolae are open up/down, so that x is the independent variable

% for plotting. (Using the form x^2/a^2 - y^2/b^2 = 1 requires that y be

% the independent variable, which is awkward programming-wise.)

clear % all variables

figure(1), hold off % start a new figure

set(gca,'FontSize',14) % adjust fontsize

xmax = 30; ymax = 20;

x = linspace(-xmax,xmax,1001); % array of x values for plot (why 1001?)

a = 5; b = 3;

y=sqrt(((-x.^2)./(b^2)+1).*a^2); % corresponding y values

plot(x,y)

hold on % add to current plot

xlabel('x')

ylabel('y')

title(['Hyperbola $y^2/a^2 - x^2/b^2 = 1$; $a$ = ', num2str(a), ...

', $b$ = ', num2str(b),'; (WR 1/21/08)'],'Interpreter','latex')

% Add axes

plot([0 0],[-ymax ymax],'k') % y axis (black line - k)

plot([-xmax xmax],[0 0],'k') % x axis

Open in new window

0
Comment
Question by:jtiernan2008
  • 2
3 Comments
 
LVL 15

Expert Comment

by:yuk99
ID: 24021978
This is because when you calculating y (line 12) you getting square root mostly from negative numbers. So your y is vector of complex numbers. You get this because when you do -x.^2, it gets square first, than adds minus.
Do (-x).^2.
0
 
LVL 15

Accepted Solution

by:
yuk99 earned 500 total points
ID: 24022077
Actually you will get different result. You probably just need what you get, but worry about the warning? Just ignore it, or you can get real part from complex y with real(y).

So in your code line 13 use:
plot(x,real(y))
0
 
LVL 1

Author Closing Comment

by:jtiernan2008
ID: 31564470
thanks a million
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
abstract class with all non abstract mentods 6 76
firstChar challenge 13 110
WPF - Tooltips for ComboBox items 5 36
Programatically extract date from website 8 66
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now