integral caculation using matlab
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Aditya
am 25 Jan. 2023
Bearbeitet: Aditya
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Assumptions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!