Solved

# Can someone please see why I am getting this error?

Posted on 2009-03-30
Medium Priority
1,007 Views
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?

``````% 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
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')
plot([0 0],[-ymax ymax],'k') % y axis (black line - k)
plot([-xmax xmax],[0 0],'k') % x axis
``````
0
Question by:jtiernan2008
• 2

LVL 15

Expert Comment

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

yuk99 earned 2000 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

ID: 31564470
thanks a million
0

## Featured Post

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
###### Suggested Courses
Course of the Month8 days, 6 hours left to enroll