Error using fprintf Unable to convert 'sym' value to 'double'.

I am new in Matlab, and basically it seems I am not using the symbolic variables correctly.
t=0:0.5:10;sm x ;
R=zeros(1,length(t),'sym');
for ii=1:length(t)
f=tanh(x)^2/(x^2)*cos((x*tanh(x))^(1/2)*t(ii));
R(ii)=(2/pi)* int(f,x,0,inf);
fprintf('%2.1f\t %3.10f\n',[t(ii); R(ii)])
end

 採用された回答

Star Strider
Star Strider 2020 年 9 月 30 日

1 投票

If you have R2016b or later, use vpaintegral:
This works (with the fprintf call corrected to eliminate the spaces between the backslant and the characters they escape, and a few other corrections):
t = 0: 0.5: 10;
syms x;
R = zeros (1, length (t),'sym');
for ii = 1: length (t)
f = tanh (x) ^ 2 / (x ^ 2) * cos ((x * tanh (x)) ^ (1/2) * t (ii));
R (ii) = (2 / pi) * vpaintegral (f, x, 0, inf);
fprintf ('% 2.1f \t% 3.10f \n', [t (ii); R (ii)])
end
.

6 件のコメント

Sila Fundora
Sila Fundora 2020 年 10 月 1 日
Thank you for the quick reply. It certainly works!!!
Star Strider
Star Strider 2020 年 10 月 1 日
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
Sila Fundora
Sila Fundora 2020 年 10 月 6 日
How?
Star Strider
Star Strider 2020 年 10 月 6 日
Clicl on the
button.
Sila Fundora
Sila Fundora 2020 年 10 月 6 日
haha, sorry. My page is in japanese and it didn't translated the bottom lol. I have to change the language. :)
Star Strider
Star Strider 2020 年 10 月 7 日
No worries!
Thank you!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by