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

1 次查看(过去 30 天)
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)

回答(1 个)

Swetha Polemoni
Swetha Polemoni 2021-3-4
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

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by