Borrar filtros
Borrar filtros

force matlab to display its symbolic calculations using indexed varaiables

1 visualización (últimos 30 días)
hello. I'm looking for a way to make matlab display the result of its output by showing the variables with their index, while doing symbolic calculations. for example in this code I want it to display x(1) instead of x1.
x=sym('x',[1 2])
y=x(1)*x(2)
e=diff(y,x(2))
now here's matlab results:
ans=
x1
what matlab did here, was to show what's contained in x(1) which is x1. the reason why I'm trying to do this, is that I need these results to create a function whose input is an indexed variable to use with fsolve because this function requires x(1), x(2) and not x1, x2. I know it is possible using strings and eval function but I need a better way.

Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de En. de 2017
x = sym('x',[1 2])
y = x(2)^2 + sin(x(1)*x(2));
e = diff(y, x(2))
f = matlabFunction(y, 'vars', {x});
fsolve(f, rand(1,2))
  2 comentarios
hosein Javan
hosein Javan el 12 de En. de 2017
thank's. I'm still interested to know how this worked. when you run this code:
x=sym('x',[1 2])
e=x(1)+x(2)
f = matlabFunction(e, 'vars', {x})
the result gives this:
f =
@(in1)in1(:,1)+in1(:,2)
could you explain how I should have known this? I didn't find any similiar example in matlab's help. it seems it will automatically vectorize inputs.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by