implicit and non linear equation by using fsolve
Afficher commentaires plus anciens
Hello
I have the following program please help me
syms R L C
R=50;
L=150e-6;
C=47e-6;
zeta=1/(2*R)*sqrt(L/C);
w=1/sqrt(L*C);
alpha1=1/(2*R*C);
T=10e-6;
alpha=exp(-alpha1*T);
A=alpha1/w*sqrt(1-zeta^2);
b=w*sqrt(1-zeta^2);
%equ1='0.004236=2*A*alpha*sin(b*T)';
%equ2='-1.982=2*alpha*cos(b*T)';
%equ3='0.9958=alpha^2';
sol=solve('(2*A*alpha*sin(b*T)=0.004236)','(2*alpha*cos(b*T)=-1.982)','(alpha^2=0.9958)') % i want to find the value of R,L and C
%eq1=(-2*exp(-1/(2*R*C)*T)*cos(1/sqrt(L*C)*sqrt(1-1/(2*R)*sqrt(L/C)^2)*T))+1.982;
%eq2=1/(2*R*C)/1/sqrt(L*C)*sqrt(1-1/(2*R)*sqrt(L/C)^2)*exp(-1/(2*R*C)*T)*sin(1/sqrt(L*C)*sqrt(1-1/(2*R)*sqrt(L/C)^2)*T)-0.00423;
%eq3=(exp(-1/(2*R*C)*T)^2-0.9958);
%sol=solve('(-2*exp(-1/(2*R*C)*T)*cos(1/sqrt(L*C)*sqrt(1-1/(2*R)*sqrt(L/C)^2)*T))+1.982','(exp(-1/(2*R*C)*T)^2-0.9958)','1/(2*R*C)/1/sqrt(L*C)*sqrt(1-1/(2*R)*sqrt(L/C)^2)*exp(-1/(2*R*C)*T)*sin(1/sqrt(L*C)*sqrt(1-1/(2*R)*sqrt(L/C)^2)*T)-0.00423');
RSol = sol.R
LSol = sol.L
CSol = sol.C
I tried to write the equation in every way as you can also look with the comment equations.
which mistake i'm making here i don't know
i'm not good in Matlab if someone has some hint then please share with me I also used fsolve for this
function F = myfun1(x)
syms R L C
zeta=1/(2*R)*sqrt(L/C);
w=1/sqrt(L*C);
alpha1=1/(2*R*C);
T=10e-6;
alpha=exp(-alpha1*T);
A=alpha1/w*sqrt(1-zeta^2);
b=w*sqrt(1-zeta^2);
F = F=[(2*A*alpha*sin(b*T)-0.004236);(2*alpha*cos(b*T)+1.982);alpha^2-0.9958;];
%F=[1/(2*R*C)/1/sqrt(L*C)*sqrt(1-1/(2*R)*sqrt(L/C)^2)*exp(-1/(2*R*C)*T)*sin(1/sqrt(L*C)*sqrt(1-1/(2*R)*sqrt(L/C)^2)*T)-0.004236;
%-2*exp(-1/(2*R*C)*T)*cos(1/sqrt(L*C)*sqrt(1-1/(2*R)*sqrt(L/C)^2)*T)+1.982;
%exp(-1/(2*R*C)*T)^2-0.9958;]
end
but when i call it by giving the exact value of R,L and C then it's not showing the correct result like
x0 = [50 150e-6 47e-6]; % Make a starting guess at the solution
[x,fval] = fsolve(@myfun1,x0)
Please tell me how can i find the value of R L and C explicitly.
Thank you so much
1 commentaire
I also used fsolve for this ... but when i call it by giving the exact value of R,L and C then it's not showing the correct result
The code you've shown does not run. It would have given you the error message,
The expression to the left of the equals sign is not a valid target for an assignment.
In any case, if the known solution does not solve the equations that means myfun1 does not contain the correct equations.
Réponses (2)
Walter Roberson
le 15 Déc 2015
1 vote
Do not assign numeric values to R, L, and C after you use "syms": that overwrites their identity as symbolic variables and leaves you with numeric expressions to solve instead of symbolic expressions.
The equations are inconsistent. You can make a substitution of variables to reduce R*C to a single variable, solve the third equation to get a value for it, and substitute that into the second equation. You can then make a substitution of variables to reduce L*C to a single variable and solve the second equation for that. When you then substitute those two values (the one for R*C and the one for L*C) in to the first equation, you will find that the first equation becomes entirely numeric and it does not balance, not by a factor of about 40.
5 commentaires
Ali Imran Siddiqui
le 15 Déc 2015
Matt J
le 15 Déc 2015
Is it possible to solve these inconsistent equation in Matlab
If you acknowledge that the equations are inconsistent, then you already know that a solution does not exist!
Walter Roberson
le 15 Déc 2015
I explored the possibility that you had made a small typing mistake in the -1.982, or that perhaps the number had not been given in enough accuracy. I replaced the -1.982 by -1.982+delta and solved for the delta that would be needed to make the equations consistent. The answer was delta slightly larger than 4, giving about a +2.0466797792678057395 instead of a -1.982 . That would be more than just a mistake in sign of -1.982 compared to +1.982, so this hypothesis is untenable.
I then explored the possibility that the -1.982 was the wrong sign and the 0.9958 was a small typing mistake, corresponding to
sol=solve(2*A*alpha*sin(b*T)=0.004236, 2*alpha*cos(b*T)=+1.982, alpha^2=0.9958+delta)
for some delta -- notice the change from -1.982 to +1.982 . Going through the steps I outlined earlier, solving from right to left, and finding numeric solutions, we find that the modified equations can be satisfied with delta approximately -0.47151092790000087021e-4 . That would modify the original 0.9958 to approximately 0.99575284890720999991 -- a number which would be rounded off to 0.9958 if you only used 4 digits after the decimal place. This is a plausible explanation.
So you did not give enough digits in your constants for a solution to be possible, and your sign was wrong on your -1.982 and should be +1.982
This leads you to
L*C = 7.2474297019037267088*10^(-9)
R*C = 0.0023495159372969332030
However, the equations do not give enough information to determine the values independently, only their ratios.
Ali Imran Siddiqui
le 16 Déc 2015
Ali Imran Siddiqui
le 21 Déc 2015
Matt J
le 15 Déc 2015
One of the problems with myfun1(x) is that it is not using the input argument x in any way. Presumably the first few lines of the function should look like
function F = myfun1(x)
R=x(1);
L=x(2);
C=x(3);
The line
syms R L C
does not belong here. You are not doing anything symbolic when using fsolve.
1 commentaire
Ali Imran Siddiqui
le 16 Déc 2015
Catégories
En savoir plus sur Creating and Concatenating Matrices 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!