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);

类别

Help CenterFile Exchange 中查找有关 Number Theory 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by