log plot in matlab

조회 수: 3 (최근 30일)
Diego Concha Fernandez
Diego Concha Fernandez 2018년 12월 2일
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