Perform elementwise substitution of vector of scalars into vector of equations.

3 visualizaciones (últimos 30 días)
Hi all,
I have a vector (t) of 1000 scalars and corresponding vector (d) of equations of (t) , I wanted to substitut
e each element of t in the corresponding equation.
I used for loop but it seems that it substitute all the values in (t) into first elemnt of (d) and then to second elemnt ans so on.. which will let the resulted vector be 1*(1000)^2 instead of 1*1000.
this is my try (I used simplified example):
a=[ 1;2;3;4;5];
syms t
v=int(a,t)
d=int(v,t)
t=[0.2;0.3;0.4;0.5;0.6];
dd=subs(d,t)

Respuestas (1)

Swetha Polemoni
Swetha Polemoni el 4 de Mzo. de 2021
Hi
It is my understanding that you want substitute every value of t in each equation d.
d =
t^2/2
t^2
(3*t^2)/2
2*t^2
(5*t^2)/2
You may find the following code snippet useful.
a=[ 1;2;3;4;5];
syms t
v=int(a,t)
d=int(v,t)
t=[0.2;0.3;0.4;0.5;0.6];
dd=zeros(5,5);
for i =1:length(t)
dd(i,:)=subs(d,t(i));
end

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by