Error in plotting the function
显示 更早的评论
%%
% we will now define our terms
global r H L
r = 0.95; H = 2.0; L = 5.0; % this are all in ft
h = 0:(H + 2*r); Nh = length(h);
V = fuelvol1(1);
vol1 = zeros(Nh, 1);
for j = 1:Nh
vol1(j) = fuelvol1(h(j));
end
V2 = fuelvol2(h);
disp(vol1);
disp(V2);
subplot(2,1,1) %first subplot
plot(h,vol1) %using h on x axis and vol1 on y axis
title('h(scalar) vs fuel volume')
xlabel('h(in range 0<h<H+2r) using scalar h')
ylabel('fuel volume')
I'm getting the error that imaginary parts of complex X/ or Y are ignored
2 个评论
Shubham Gupta
2019-9-30
Can you please share the code for 'fuelvol1' function ?
Initial guess is that your fuelvol1 function is generating complex data, which is why plot function is generating warning that it will only plot real part of the complex number and will ignore the imaginary part.
Peter Njoroge
2019-9-30
回答(2 个)
Sulaymon Eshkabilov
2019-9-30
0 个投票
Hi,
Note that with the plot command you can plot only real parts of your complex valued data. To plot imaginary parts of your computed data, you had better separate them out for real and imaginary parts with real() and imag().
Good luck.
Walter Roberson
2019-9-30
0 个投票
Your h starts from 0. d = h - H is 0 - 2 which is -2. (r-d)/r is (0.95-(-2))/0.95 = +3 something. 2*r*d-d^2 is 2*0.95*(-2) - (-2)^2 = -3.8-4 = -7.8. sqrt() of that is complex valued with no real magnitude, somewhere around 2.7*sqrt(-1). You multiply the sqrt by (r-d) which is 2.95 getting a something on the order of -6*sqrt(-1). That is subtracted from the +3ish so you get +3ish + 6ish*sqrt(-1). You acos() that and since it is complex the result is complex, but furthermore if you had avoided the sqrt(-1) and taken the sqrt root of a positive value, you would be working on acos of a value outside -1 to +1 so the acos would be complex valued.
It makes no sense for a fuel consumption to be complex valued. Either your equations are wrong or your initial conditions are wrong.
Note by the way that 0:(H+2*r) will only take on integer values. You should probably consider linspace()
类别
在 帮助中心 和 File Exchange 中查找有关 Grid Lines, Tick Values, and Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!