fplot not showing any value

조회 수: 2 (최근 30일)
Samuel
Samuel 2024년 5월 27일
편집: Torsten 2024년 5월 28일
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에서 Line Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by