integral caculation using matlab

1 回表示 (過去 30 日間)
Carc
Carc 2023 年 1 月 25 日
コメント済み: Aditya 2023 年 1 月 25 日
I don't know what's error in my code. Could you give me some advice?
x = (10^-5:10^1);
y = 0.453 .* exp(-1.036 .* x) .* sinh((2.29.* x).^0.5);
sym m
m = int(y, x, 0.0625, inf);
semilogx(x,y)
hold on
semilogx(x,m)

回答 (1 件)

Aditya
Aditya 2023 年 1 月 25 日
編集済み: Aditya 2023 年 1 月 25 日
Hi, I understand that you are getting error when running the above script. The reason why you are getting an error is because int expects the expression, y to be symbolic.
To solve this, you need to create x as a symbolic variable. Change the line `x = (10^-5:10^1);` to `syms x;`
You can read more about symbolic variables here .
For running your full script, you also need to modify how the script is plotting. Here is how you can modify your scipt to use semilogx:
syms x;
y = 0.453 * exp(-1.036 * x) * sinh((2.29* x)^0.5);
m = int(y, x, 0.0625, inf);
x_i = (10^-5:10^1);
y_i = zeros(numel(x_i),1);
m_i = zeros(numel(x_i),1);
for i = 1:numel(x_i)
y_i(i) = subs(y,x,x_i(i));
m_i(i) = subs(m,x,x_i(i));
end
figure;
semilogx(x_i,y_i)
semilogx(x_i,m_i)
For plotting symbolic variables, however, fplot is used. Here is how the script would look like with fplot:
syms x;
y = 0.453 * exp(-1.036 * x) * sinh((2.29* x)^0.5);
m = int(y, x, 0.0625, inf);
figure;
fplot(x,y);
hold on;
fplot(x,m);
  2 件のコメント
Carc
Carc 2023 年 1 月 25 日
編集済み: Carc 2023 年 1 月 25 日
It's not work, though.
Aditya
Aditya 2023 年 1 月 25 日
@Carc I have updated the answer

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by