Numerically Solving Complex Equation
28 次查看(过去 30 天)
显示 更早的评论
I am trying to solve the following equation numerically:
Where I am trying to solve for omega in terms of k and both are complex and nonzero. Lamda_D and v_Ts are both real. Both contain real and imaginary components. Z is the plasma dispersion function. Here is how I implemented it in code:
% User Inputs
ne = (1E+8); %charge #/m^3
ni = (1E+8); %charge #/m^3
percIon = 1; % Percentage of molecules that are ions
d = 70; % Electrode spacing in (cm)
z = 1; % Effective charge of ions in plasma
Ti = 465;
Te = 471;
% Natural Constants
u0 = pi*4E-7; %(H/m)
ep0 = 8.8542E-12; %Vacuum constant (Farads/meter)
q = 1.60218E-19; %Absolute charge of electron (Coulombs)
k_B = 1.380649E-23; %Joule/K
m_i = 1.667E-27;
m_e = 9.11E-31;
% Calculations
v_Ti = sqrt((3*k_B*Ti)/m_i);
v_Te = sqrt((3*k_B*Te)/m_e);
%In (K)
Num = (ep0*k_B)/q^2;
Den = ne/Te + z^2*ni/Ti;
lambdaD = sqrt(Num/(percIon*Den));
syms omega k
squi_i = omega / (k * v_Ti * sqrt(2));
squi_e = omega / (k * v_Te * sqrt(2));
plasDispFun_Di = -2*(1 + squi_i*1i*sqrt(pi)*exp(-squi_i^2)*(1 + erf(1i*squi_i)));
plasDispFun_De = -2*(1 + squi_e*1i*sqrt(pi)*exp(-squi_e^2)*(1 + erf(1i*squi_e)));
eps = 1 - plasDispFun_De/(2*k^2*lambdaD) - plasDispFun_Di/(2*k^2*lambdaD);
sol = vpasolve(eps,[omega k]);
I tried using vpasolve but I get a solution that is empty.
[sol.omega sol.k]
ans =
Empty sym: 0-by-2
Does anyone know what I may be doing incorrectly here? Or is this not the proper function to use for this application?
5 个评论
Torsten
2024-1-16
If you make a surface plot of abs(eps) over an arbitrary 2d-domain, you will see that abs(eps) does not have a zero. So it's not due to MATLAB, but due to your function definition that "fsolve" does not succeed.
回答(1 个)
Hassaan
2024-1-11
- Define the Equations Symbolically:Use symbolic math to define your equations. Since you have complex numbers, make sure to use syms with the 'complex' option.
- Use vpasolve with Initial Guesses:Providing initial guesses close to the expected solutions can help vpasolve find a solution.
- Adjust Tolerances if Necessary:If the solution is sensitive, you may need to adjust the tolerances for the solver.
- Separate Real and Imaginary Parts:If vpasolve has trouble with the complex equation, you might need to separate the real and imaginary parts of the equation.
% Define the symbolic variables and equations
syms k real;
syms omega complex;
% Given constants (you will need to define these with actual values)
lambda_D = ...; % replace with actual value
v_Ts = ...; % replace with actual value
% Define xi_s in terms of omega and k
xi_s = omega / (k * v_Ts * sqrt(2));
% Define Z'(xi_s)
Z_prime = -2 * (1 + xi_s * i * sqrt(pi) * exp(-xi_s^2) * (1 + erf(i * xi_s)));
% Main equation to solve
eqn = 1 - (Z_prime / (2 * k^2 * lambda_D^2)) == 0;
% Solve the equation numerically for omega
% Provide an initial guess for omega if known
init_guess = ...; % replace with your initial guess for omega
options = optimset('Display', 'off', 'TolFun', 1e-6, 'TolX', 1e-6); % Adjust tolerances as needed
[omega_sol, ~, exitflag] = vpasolve(eqn, omega, init_guess, 'Options', options);
% Check if a solution was found
if exitflag
fprintf('Solution found: omega = %s\n', vpa(omega_sol, 6));
else
fprintf('No solution found.\n');
end
Replace the ... with the actual values you have for the constants and the initial guess for omega.
Please make sure to use your actual values for lambda_D, v_Ts, and an initial guess for omega that is close to where you expect the root to be. The initial guess can significantly affect the success of vpasolve in finding a solution. If you're unsure of the initial guess, you might need to explore the parameter space or use a numerical solver like fsolve that can handle complex numbers with appropriate options set.
---------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!