fplot not showing any value
4 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
SAI SRUJAN
on 28 May 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!
More Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!