Filter löschen
Filter löschen

fplot not showing any value

1 Ansicht (letzte 30 Tage)
Samuel
Samuel am 27 Mai 2024
Bearbeitet: Torsten am 28 Mai 2024
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 Kommentare
Samuel
Samuel am 28 Mai 2024
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 am 28 Mai 2024
Bearbeitet: Torsten am 28 Mai 2024
Look e.g. at the log-expressions in your function Y. Most probably, the argument x for log(x) becomes negative over [0 12].

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

SAI SRUJAN
SAI SRUJAN am 28 Mai 2024
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 Kommentar
Samuel
Samuel am 28 Mai 2024
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 ;)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Produkte


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by