Error in plotting the function
Mostra commenti meno recenti
%%
% 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 Commenti
Shubham Gupta
il 30 Set 2019
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
il 30 Set 2019
Risposte (2)
Sulaymon Eshkabilov
il 30 Set 2019
0 voti
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.
1 Commento
Peter Njoroge
il 30 Set 2019
Walter Roberson
il 30 Set 2019
0 voti
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()
Categorie
Scopri di più su Grid Lines, Tick Values, and Labels in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!