Warning: Imaginary parts of complex X and/or Y arguments ignored

4 views (last 30 days)
Hi eveyone,
I am not an experienced Matlab user at all and I don't understand why I am getting this error. I had this code work before in another program but when I changed the graphing interval from (-1,(pi/2)) to (-pi,pi) I got this error. The code that I had run before looks like this
f = log(1+x);
T=taylor(f,'order',6);
pretty(T)
figure()
x_values=linspace(-1,(pi/2));
f_values = log(1+x_values);
T_values=subs(T,x_values);
plot(x_values,f_values);
hold on; plot(x_values,T_values,':');
All I did for the new code was change the interval from (-1,(pi/2)) to (-pi,pi) and changed the degree of the taylor polynomial from 5 to 7.
f = log(1+x);
T=taylor(f,'order',8);
pretty(T)
figure()
x_values=linspace(-pi,pi);
f_values = log(1+x_values);
T_values=subs(T,x_values);
plot(x_values,f_values);grid on;
hold on; plot(x_values,T_values,':');
I am getting the error for the f_values = log(1+x_values) part and I don't understand why I am. If someone could please help out it would be great because I have no clue what I am doing or why this isn't working. Thanks so much!

Answers (1)

Torsten
Torsten on 3 Aug 2015
(1-pi) < 0, so log(1+x) does not return real values.
Best wishes
Torsten.

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!