Output numeric array from symbolic evaluation

I am trying to evaluate some symbolic functions at specific datapoints using nested loops and output the results to an array.
While the results in the output window are the numeric values, the array contents are not.
How can I correct this to get the numeric results in the array?
syms d1 d2 d3 ma mb x0 u3 u4;
ma = (d2-d1);
mb = (d3-d2);
x0 = ma*mb;
u3 = diff(x0,d3)
u4 = diff(x0,d2)
T = [];
next = 1;next1 = 1;next2=1;
for next2 = 1:35:5;
for next = 1:4;
%example values
b1 = 1*next/2;
b3 = b1+2;
for next1 = [0.05,0.1,0.4,0.65,0.9];
b2 = b1*next1;
z=vpa(subs(u3,{d1,d2,d3},{b1,b2,b3}),4)
g=vpa(subs(u4,{d1,d2,d3},{b1,b2,b3}),4)
T = [T;b1,b2,b3,z,g];
end
end
end
T

1 件のコメント

Rose Montgomery
Rose Montgomery 2021 年 1 月 13 日
編集済み: Rose Montgomery 2021 年 1 月 13 日
Follow up for Star Strider - now how do I get T into Excel? I tried array2table with no luck.
Never mind, I got it....use double to convert T from vpa to numbers

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

 採用された回答

Star Strider
Star Strider 2021 年 1 月 13 日

0 投票

After the loops:
T = vpa(T)
creates the entire array as decimal fractions.

5 件のコメント

Rose Montgomery
Rose Montgomery 2021 年 1 月 13 日
That did the trick, thank you, @Star Strider!!
Star Strider
Star Strider 2021 年 1 月 13 日
As always, my pleasure!
Star Strider
Star Strider 2021 年 1 月 13 日
To write ‘T’ to an Excel file:
OutMatrix = double(T);
writematrix(OutMatrix, 'Rose Montgomery T.xlsx')
and to read it:
InMatrix = readmatrix('Rose Montgomery T.xlsx')
.
Rose Montgomery
Rose Montgomery 2021 年 1 月 13 日
Thanks again, Star Strider!!
Star Strider
Star Strider 2021 年 1 月 13 日
As always, my pleasure!

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

その他の回答 (0 件)

製品

リリース

R2020b

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by