# integral caculation using matlab

2 vues (au cours des 30 derniers jours)
Carc le 25 Jan 2023
Commenté : Aditya le 25 Jan 2023
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)
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (1)

Modifié(e) : Aditya le 25 Jan 2023
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;`
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 commentairesAfficher AucuneMasquer Aucune
Carc le 25 Jan 2023
Modifié(e) : Carc le 25 Jan 2023
It's not work, though.
@Carc I have updated the answer

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Number Theory dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by