How to find the complex root for this equations

Hi guys!
I'M new using Matlab .
i'm trying to finding the roots for an effective permittivity equation in two form Quadratic and Nonlinear and it Should have the Same solution
any suggestion how to solve equations and find roots.
%Quadratic Equation
function ere= roots
p=[0.23,0.25,0.27]; % concentration of sample
er1=(1+1.8*10^14*i); % Phase one Permittivity
er2=(2.5+2.5*10^-3*i); % Phase two Permittivity
ere=(1./4).*(((3.*p-1).*er1)+((2-3.*p).*er2)+((((3.*p-1).*er1)+((2-3.*p).*er2)).^2+8.*er1.*er2).^0.5);
% effective permittivity
plot(p,ere)
end
Nonlinear Equation
function fval=eqns(ere)
P=[0.23,0.25,0.27];
er1=(1+1.8*10^14*1i);
er2=(2.5+2.5*10^-3*1i);
fval=((P).*((ere-er1)./(er1-2.*ere)))+((1-P).*((ere-er2)./(er2-2.*ere)));
plot(p,ere)
end

 Réponse acceptée

First, one important suggestion: Don't call your function as one Matlab function (roots, in fact is the one that you need to call).
After that, the equation (3) is trivial, you get the value of ere directly as you have in your function:
p = [0.23,0.25,0.27]'; % concentration of sample
er1 = (1+1.8*10^14*i); % Phase one Permittivity
er2 = (2.5+2.5*10^-3*i); % Phase two Permittivity
ereEQ3 = (1./4)*(((3*p-1)*er1) + ((2-3*p)*er2) + ((((3.*p-1)*er1) + ((2-3*p)*er2)).^2+8*er1*er2).^0.5);
For the other equation (2), yo need to obtain the roots of the second orden polynomial. One option is to use the roots function. (Note that you will obtain 2 solutions for each value of p, and only one is the same than the one obtained with the previous equation).
pol = [2+p*0, (-2+3*p)*er2 + (1-3*p)*er1, -er1*er2+p*0];
ereEQ2 = arrayfun(@(i) roots(pol(i,:)),1:numel(p),'uni',0);

2 commentaires

Ammar Ahmed
Ammar Ahmed le 10 Juin 2019
hanks for replying i tried to use your command
pol = [2+p*0, (-2+3*p)*er2 + (1-3*p)*er1, -er1*er2+p*0];
ereEQ2 = arrayfun(@(i) roots(pol(i,:)),1:numel(p),'uni',0);
but it give me Error
Error using roots
Too many input arguments.
Error in @(i)roots(pol(i,:))
It seems that you still have your function called roots. Change the name of your function, run this command in the command window:
clear all
And try to execute my code

Connectez-vous pour commenter.

Plus de réponses (1)

Ammar Ahmed
Ammar Ahmed le 10 Juin 2019

0 votes

thanks for replying i tried to use your command
pol = [2+p*0, (-2+3*p)*er2 + (1-3*p)*er1, -er1*er2+p*0];
ereEQ2 = arrayfun(@(i) roots(pol(i,:)),1:numel(p),'uni',0);
but it give me Error
Error using roots
Too many input arguments.
Error in @(i)roots(pol(i,:))

Catégories

En savoir plus sur Numerical Integration and Differential Equations dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by