semilogy plotting in domain

2 Ansichten (letzte 30 Tage)
Nima Vali
Nima Vali am 22 Sep. 2020
Bearbeitet: Nima Vali am 22 Sep. 2020
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')

Antworten (0)

Kategorien

Mehr zu Introduction to Installation and Licensing 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!

Translated by