fplot not showing any value

1 次查看(过去 30 天)
Hello, I'm fairly new to Matlab, and I need to plot a function. This function is the double anti-derivative of another function.
Using fplot to plot the first function works, but it doesn't show any value for the second function... Here is my code :
syms x D(x) Dint(x) g(x) f(x)
E=2.1*10^11
L=12
F=2000
K=1500
C=0.28
e=0.008
a=0.00076
P=3000
w=77008.5
% Fonctions
D(x)=0.2191-a*x
Dint(x)=D(x)-2*e
f(x)= (-F*(L-x)-K*C*(D(x))*(L-x)^2/2)/(E*3.14*(D(x)^4-Dint(x)^4)/64)
g(x)=int(f(x)) - subs(int(f(x)),x,0)
Y(x)=int(g(x)) - subs(int(g(x)),x,0)
subs(Y,x,0)
double(subs(Y,x,12))
% Debug
fplot(f,[0 12])
fplot(Y,[0 12])
I am using Matlab R2024a.
Thanks in advance !
  3 个评论
Samuel
Samuel 2024-5-28
I didn't realise my function was returning complex values... This is more a math question but how can the integral of a real function return a complex function ?
Torsten
Torsten 2024-5-28
编辑:Torsten 2024-5-28
Look e.g. at the log-expressions in your function Y. Most probably, the argument x for log(x) becomes negative over [0 12].

请先登录,再进行评论。

采纳的回答

SAI SRUJAN
SAI SRUJAN 2024-5-28
Hi Samuel,
I understand that you are facing an issue trying to plot a complex-valued function.
A straightforward approach is to plot the real and imaginary parts of the function separately. We can also use 'plot3' function, this method plots the real part of the input on one axis, the imaginary part on another, and the magnitude of the output on the third axis.
Please follow the below code sample to proceed further,
Y = @(z) exp(1i*z);
% Create a figure for the Real part of Y
figure;
subplot(2, 2, 1); % Subplot 1
fplot(@(z) real(Y(z)), [0 12]);
% Create a subplot for the Imaginary part of Y
subplot(2, 2, 2); % Subplot 2
fplot(@(z) imag(Y(z)), [0 12]);
% Create a subplot for the Magnitude of Y
subplot(2, 2, 3); % Subplot 3
fplot(@(z) abs(Y(z)), [0 12]);
% Create a subplot for the Phase of Y
subplot(2, 2, 4); % Subplot 4
fplot(@(z) angle(Y(z)), [0 12]);
sgtitle('Visualization of Y(z) = e^{iz}'); % Super title for the figure
% 3D Plot using plot3
figure;
z = linspace(-2*pi, 2*pi, 1000);
plot3(real(Y(z)), imag(Y(z)), abs(Y(z)), 'LineWidth', 2);
For a comprehensive understanding of the 'plot3','fplot' and 'subplot' functions in MATLAB, please refer to the following documentation.
I hope this helps!
  1 个评论
Samuel
Samuel 2024-5-28
I didn't realise my function was returning complex values... When x is in [ 0 12 ], the imaginary part is equal to 0 so I didn't notice this. Thanks ;)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

标签

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by