log plot in matlab

12 次查看(过去 30 天)
Diego Concha Fernandez
Hello,
I am trying to plot a log function.
So , i first calculate the integral of a function.
Second, make a simpson approximation,
Third , calculate the error between the integral and each approximation from n = 2 to n= 100000;
And fourth I try to plot a log graph having the x axis : n from 2 to 100000 , and its corresponding error on the y axis... However, the graph its not plotting any results, can anyone please help me out with this?
1)
function [I] = actualintegral(x)
fun = @(x) exp(-x.^2);
xmin=0;
xmax=1;
I= integral(fun,xmin,xmax);
end
...
2)
function[S] = simpson(n)
f=@ (x)exp(-x^2);
a= 0 ;
b= 1;
h = (b-a)/n;
g = f(a)+f(b);
for i = 1:2:n-1
g=g+4*f(a+i*h);
end
for i= 2:2:n-2
g= g+2*f(a+i*h);
end
S =h/3 * g;
end
...
3)
function [error] = errort(I,S,n)
I = actualintegral();
for n=2:100:100000
S = simpson (n);
error = abs(I - S)
end
end
...
4)
function [P] = logplot(I,S,n)
x = logspace(0,4);
y = errort ();
loglog(x,y,'-s')
grid on
end

回答(0 个)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by