Borrar filtros
Borrar filtros

matlab code which works on 2022a is not working in 2023b

2 visualizaciones (últimos 30 días)
sudhir
sudhir el 29 de Mayo de 2024
Editada: Infinite_king el 30 de Mayo de 2024
syms x y(x)
y1 = x-y^2
%define the function
%define the initial values
x0 = 0
y0 = 1
X = 0.2
h = 0.1
% differentiating successively
y2 = (diff(y1))
y3 = diff(y2)
y4 = diff(y3)
% differentiating order successively
f1=(diff(y1,x,1))
f2=diff(y1,x,2)
f3=diff(y,x,3)
% substitution of values
y10 = subs(y1,{x,y(x)},[x0,y0])
y20 = (subs(y2,{x,y(x),f1},[x0,y0,y10]))
y30 = (subs(y3,{x,y(x),f1,f2},[x0,y0,y10,y20]))
y40 = (subs(y4,{x,y(x),f1,f2,f3},[x0,y0,y10,y20,y30]))
%calculating Taylor series formula
for i=x0+h:h:X
y = y0 + (x-x0)*y10 + (((x-x0)^2)/2)*y20 + (((x-x0)^3)/6)*y30 + (((x-x0)^4)/24)*y40
Y = subs(y,x,i);
fprintf('Value of y at x=%0.1f is %.4f\n',i,Y)
end
  4 comentarios
sudhir
sudhir el 29 de Mayo de 2024
y1(x) =
x0 = 0
y0 = 1
X = 0.2000
h = 0.1000
y2(x) =
y3(x) =
y4(x) =
f1(x) =
f2(x) =
f3(x) =
y10(x) =
1
y20(x) =
y30(x) =
y40(x) =
y(x) =
Y(x) =
Value of y at x=0.1 is
Error using fprintf
Conversion to double from sym is not possible.
this is error i am getting
Infinite_king
Infinite_king el 29 de Mayo de 2024
Editada: Infinite_king el 30 de Mayo de 2024
I tried to run your code on MATLAB 2022a, but it showed the same exact error as above. The 'subs' function is unable to resolve the symbolic expression with the given substitutions.
What are you trying to achieve? Are you attempting to find the Taylor series expansion of a multivariate function?

Iniciar sesión para comentar.

Respuestas (1)

Ganesh
Ganesh el 29 de Mayo de 2024
From my understanding you are encountering an error with your given code while executing it in R2023a, but not when executing it in R2021b. However, I find that an error occurs while using both the versions of MATLAB.
The error arises as Y does not evaluate to a valid double number after using the subs() function. Kindly ensure that the implementation of your algorithm is correct. From a simple overview, as "y2","y3" and "y4" is already successively differentiated, substituting "f1","f2" and "f3" seems to cause redundancy.
Later, you need to ensure to convert the variable "Y" to a "double()" value in order to avoid incosistency.
Hope this answer helps!

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by