How to find the real roots and index root?
33 次查看(过去 30 天)
显示 更早的评论
syms x m y M %H R_c R_a p R
%---------------------------------------------------
%Initilization
%---------------------------------------------------
U=zeros(1,'sym');
A=zeros(1,'sym');
B=zeros(1,'sym');
C=zeros(1,'sym');
D=zeros(1,'sym');
E=zeros(1,'sym');
F=zeros(1,'sym');
series(x)=sym(zeros(1,1));
%---------------------------------------------------
%Parameters
%---------------------------------------------------
l=0.5;
%M=0.5;
H=0.5;
R_c=0.5;
R_a=0.25;
p=0.8;
R=0.25
%---------------------------------------------------
%Initial condition
%---------------------------------------------------
U(1)=y
U(2)=0
for i=1:14
U(i+2)=m;
A(1)=0;
B(1)=0;
C(1)=0;
for j=1:i
A(1)=A(1)+U(j)*(i-j+1)*(i-j+2)*U(i-j+3);
B(1)=B(1)+j*U(j+1)*(i-j+1)*U(i-j+2);
C(1)=C(1)+U(j)*U(i-j+1);
end
variable_m=(1+4*R_c)*i*(i+1)*U(i+2)+l*A(1)+l*B(1)-R_a*C(1)-M*(1-p)*U(i)-H*U(i)-R*U(i);
variable=solve(variable_m,m);
U(i+2)=variable;
end
for k=1:6
series(x)=simplify(series(x)+U(k)*(power(x,k-1)));
end
series
e1=subs(series,x,1);
e2=e1-1
root=solve(e2,y)
var2 = vpa(root)
%%%%%%%%%%%%%%%%%%%%%%%%HOW TO FIND THE REAL ROOT %%%%%%%%%%%%%%%%%%%
series_M=subs(series, y,root(1))
Fin_efficiency=int(series_M,x,0,1)
var = vpa(Fin_efficiency)
M=0:5
row=0;
eta=zeros(length(M))
for i=1:length(M)
row=row+1
eta(row)=var(M(row))
end
plot(M,eta)
%-----------------------------------------------------------------------------------------
the following error apper where the error remaining
Array indices must be positive integers or logical values.
R_tilde = builtin('subsref',L_tilde,Idx);
But the indices are positive
3 个评论
Torsten
about 2 hours 前
编辑:Torsten
about 1 hour 前
You shouldn't use "series" as a function name.
"series" is reserved to compute the series of a given function within the Symbolic Toolbox:
Further use
root=solve(e2,y,'MaxDegree',4)
instead of
root=solve(e2,y)
Since Fin_efficiency depends on M,
var = vpa(Fin_efficiency)
doesn't make sense - you can't get a numerical value for a symbolic expression that still depends on a symbolic variable.
Paul
18 minutes 前
Can the code be refactored so that it doesn't need to find the root until the value of M is known and assigned?
回答(1 个)
Walter Roberson
about 1 hour 前
You need to be careful working with root indices.
There is, as far as I know, no documentation as to what the root indices actually mean. We know that for any given set of purely numeric coefficients, that the root indices are consistent, but we do not know how the root indices match for a different set of numeric coefficients. We do not know what the root indices mean if there are unresolved symbolic variables (that are not being solved for) among the coefficients.
The indexing does not appear to relate to any particular formula for the roots. Suppose you had
syms z M
f = solve(z^4+z+M,z)
then if you were to use
g = solve(z^4+z+M, z, 'Maxdegree', 4)
then the elements of g are fixed individual formulas for the roots. It would be reasonable to ask whether root(,1) from f corresponds to the first formula (or at least to one specific one of the formulas.) The answer appears to be NO, that the meaning of root(,1) can move between specific formulas as M is given different numeric values.
In practice, the root indices for any one set of numeric coefficients appear to somehow relate to the complex angle; the first root appears to relate to the root with the smallest angle. This is not promised anywhere that I have seen documented.
Thus, as M changes smoothly, the relative complex angles of the different formulas changes, and root(,1) appears to always select the formula that currently has the smallest complex angle.
This can be proven by plotting the outputs of the different formulas, and simultaneously plotting the output of root(,1) : the output of root(,1) will jump at places whereas the formulas move smoothly.
Because of this, you should probably not be using
series_M=subs(series, y,root(1))
as that is going to get you a particular index number, but the meaning of the index number is going to change as you vary M.
You should instead consider using
root = solve(e2, y, 'Maxdegree', 4);
and then selecting one of the outputs.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







