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

2 ビュー (過去 30 日間)
Eamon Henikish
Eamon Henikish 2021 年 3 月 1 日
コメント済み: Eamon Henikish 2021 年 3 月 4 日
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
  1 件のコメント
Eamon Henikish
Eamon Henikish 2021 年 3 月 4 日
Thanks @Swetha Polemoni , but this gives a (5*5) matrix,
what I wanted a (5*1) matrix just like d!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by