Plotting variables from an implicit function
17 views (last 30 days)
Show older comments
d=0.2; fs=250e3; Vo=40; C=126e-12; V=425; I=75;
A1=Vo/Vdc; A2=2*fs*Io/Vdc; A3=Cp*(Vdc/Io)^2;
f = dmin - A1/n - A2*n*L*( 1+sqrt( 1-A3/(n*L) ) );
fimplicit(f,[0.1e-6 50e-6 0.01 0.5])
I am getting a blank plot after executing the above statements. Kindly let me know where I am going wrong.
Thank you.
0 Comments
Accepted Answer
John D'Errico
on 14 Aug 2023
fimplicit plots the lines where your function is ZERO in that region. Is it ever zero? Probably not.
dmin=0.2; fs=250e3; Vo=40; Coss=126e-12; Vdc=425; Io=75;
Cp=2*Coss;
A1=Vo/Vdc; A2=2*fs*Io/Vdc; A3=Cp*(Vdc/Io)^2;
First, fix your function so it is properly vectorized. Note my use of the dotted operators. You don't need them for scalar multiplication.
f = @(L,n) dmin - A1./n - A2*n.*L.*(1+sqrt(1-A3./(n.*L)));
Look at a sample value of your function in that interval. This also lets me verify if the function evaluates properly.
f(1e-5,.1)
fimplicit(f,[0.1e-6 50e-6 0.01 0.5])
Again, the blank plot suggests there are no places in that region where the function crosses zero. At least, no place that was found by fimplicit. Be very careful however, since your intervals cover many powers of 10. So something might happen near zero, and fimplicit missed it.
We can take a look at the surface, to see what may be happening.
fsurf(f,[0.1e-6 50e-6 0.01 0.5])
And that suggests it comes close to zero in one corner of the domain, near [0,.5]. So if I change the limits just a bit, we might find a solution.
fimplicit(f,[0.1e-7 1e-6 0.4 0.6])
grid on
And indeed we did, but we had to look a bit outside of your original domain.
0 Comments
More Answers (2)
Steven Lord
on 14 Aug 2023
Let's vectorize your function and see what it looks like when you plot it as a surface.
dmin=0.2; fs=250e3; Vo=40; Coss=126e-12; Vdc=425; Io=75;
Cp=2*Coss;
A1=Vo/Vdc; A2=2*fs*Io/Vdc; A3=Cp*(Vdc/Io)^2;
I changed your code to use element-wise multiplication and division rather than matrix multiplication and division. See this documentation page for more information.
f = @(L,n) dmin - A1./n - A2*n.*L.*( 1+sqrt( 1-A3./(n.*L) ) );
fsurf(f,[0.1e-6 50e-6 0.01 0.5])
What does fimplicit do? From the fimplicit documentation: "fimplicit(f) plots the implicit function defined by f(x,y) = 0 over the default interval [-5 5] for x and y." Based on this surface, I'd say that call should plot at most a handful of points and that's only if the upper-left corner of the plot actually reaches the zero plane. Does it?
f(0.1e-6, 0.5)
Yes, barely. And if you look very carefully at that corner of your fimplicit plot you'll see just a hint of a blue line. So fimplicit behaved correctly.
0 Comments
Ruchika
on 14 Aug 2023
Edited: Ruchika
on 14 Aug 2023
Hi, based on my understanding, you want to plot the equation using 'fimplicit' but this function aims to plot implicit functions and the nature of your equation might not be suitable for this approach. It seems that your equation involves both square roots and divisions, which can complicate the process of plotting it directly using 'fimplicit'.
In the following code, I've created a meshgrid of L and n values and evaluated the equation over that grid to obtain the z values. The 'surf' plot essentially visualizes the variation of the equation's value in a 3D space. Please feel free to adjust the range and number of points in the linspace calls according to your needs.
dmin = 0.2;
fs = 250e3;
Vo = 40;
Coss = 126e-12;
Vdc = 425;
Io = 75;
Cp = 2 * Coss;
A1 = Vo / Vdc;
A2 = 2 * fs * Io / Vdc;
A3 = Cp * (Vdc / Io)^2;
% Define the equation
f = @(L, n) dmin - A1 ./ n - A2 .* n .* L .* (1 + sqrt(1 - A3 ./ (n .* L)));
% Define the range of values for L and n
L_range = linspace(1e-6, 50e-6, 100); % Adjust the range and number of points
n_range = linspace(0.01, 0.5, 100); % Adjust the range and number of points
% Create a meshgrid of L and n values
[L, n] = meshgrid(L_range, n_range);
% Evaluate the equation over the meshgrid
z = f(L, n);
% Plot the equation
figure;
surf(L, n, z);
xlabel('L');
ylabel('n');
zlabel('Equation Value');
title('Plot of the Equation');
grid on;
To learn more about the above functions, please check out the MathWorks documentation links below:
0 Comments
See Also
Categories
Find more on Surface and Mesh 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!