symbolic substitution error and convert

28 views (last 30 days)
yogeshwari patel
yogeshwari patel on 18 Jan 2026 at 2:55
Commented: Walter Roberson on 21 Jan 2026 at 9:15
syms x
series1(x)=sym(zeros(1));
series2(x)=sym(zeros(1));
U=zeros(1,2,'sym');
syms x m z
alpha=15;
gamma=0.01;
U(1)=m;
U(2)=0;
A(1)=zeros(1,'sym');
for k=1
U(k+2)=z;
A(1)=0;
for m=1:k
A(1)=A(1)+U(m)*(k-m+1)*(k-m+2)*U(k-m+3);
end
B=k*(k+1)*U(k+2)+alpha*A(1)-gamma*U(k)
D=simplify(solve(B,z))
U(k+2)=D
end
B = 
D = 
U = 
disp(U(3))
for k=1:3
series1(x)=simplify(series1(x)+U(k)*(power(x,k-1)));
end
series1
series1(x) = 
e1=subs(series1,x,1);
e=e1-1;
format long
accuracy=input('enter the accuracy')
Error using input
Support for user input is required, which is not available on this platform.
f=e(x)
g=inline(f)
g=inline(f)
a=input('enter the ist approximation=')
b=input('enter the 2nd approximation=')
fa=feval(g,a)
fb=feval(g,b)
while fa*fb>0
a=input('enter the ist approximation=')
b=input('enter the 2nd approximation=')
fa=feval(g,a)
fb=feval(g,b)
end
for i=1:50
c=(a+b)/2;
fc=feval(g,c);
disp([i a fa b fb c fc abs(b-a)])
if fc==accuracy
fprintf('the root of the equation is %f',c)
break;
elseif abs(b-a)<=accuracy
fprintf('the root of the equation is %f',c)
break;
elseif fa*fc<=0
b=c;
fb=fc;
else
a=c;
fa=fc;
end
end
fprintf('the value of c=%f', c)
series2(x)=subs(series1,m,c)
toc
the synatx is correct but still the value of m is not substituted in
  4 Comments
yogeshwari patel
yogeshwari patel on 18 Jan 2026 at 3:57
0.99999 is the exact value . I am interseted in syntax subs . why the value is not replace by c
Walter Roberson
Walter Roberson on 18 Jan 2026 at 5:15
You are saying that you enter 0.99999 in response to
accuracy=input('enter the accuracy')
and as well in response to each of the
a=input('enter the ist approximation=')
b=input('enter the 2nd approximation=')
???

Sign in to comment.

Accepted Answer

Broy
Broy on 21 Jan 2026 at 5:00
Moved: Walter Roberson on 21 Jan 2026 at 9:15
@yogeshwari patel, a possible reason the value of m is not being substituted at the end is that you are overwriting the symbolic variable m with a numeric loop counter inside your first for loop.

More Answers (0)

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!