semilogy plotting in domain
3 views (last 30 days)
Show older comments
hello evryone
I hope someone can help me doing my project, as I am very new to Matlab; I am going to plot by f'j , approxomated by three methods. I neeed to plot it by semilogy in domain x ∈[0.1,0.4]. I am not sure if the plot that is given by my code is right; can someone give me some tips?
clc; clear all;close all;
f = @(x) sin(5*x)./x.^3;
h = 0.0005;
x = 0.1:h:0.4;
n = length(x);
y=f(x);
dyforward = zeros(n,1);
dycentral = zeros(n,1);
dyforthcent = zeros(n,1);
for i=2:n-1
dyforward(i) = (y(i+1)-y(i))/h;
dycentral(i) = (y(i+1)-y(i-1))/(2*h);
end
for i=3:n-3
dyforthcent (i)=(-y(i+2)+8*y(i+1)-8*y(i-1)+y(i-2)).*(1/12./h);
end
figure;
grid on;
hold on;
semilogy(x,y,'r');
semilogy(x(2:end-1), dyforward(2:end-1),'linewidth',1);
semilogy(x(2:end-1), dycentral(2:end-1),'linewidth',2);
semilogy(x(3:end-3), dyforthcent(3:end-3),'linewidth',3);
legend('y', 'dyforward', 'dycentral', 'dyforthcent')
0 Comments
Answers (0)
See Also
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!