How to find the real roots and index root?
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.
Error in indexing (line 936)
R_tilde = builtin(‘subsref’,L_tilde,Idx);
But the indices are positivesyms 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.
Error in indexing (line 936)
R_tilde = builtin(‘subsref’,L_tilde,Idx);
But the indices are positive 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.
Error in indexing (line 936)
R_tilde = builtin(‘subsref’,L_tilde,Idx);
But the indices are positive root and index issue MATLAB Answers — New Questions









