From: Kiril on
Hi folks, I have to use difference equation to find second derivative of sin function.
This is the function g1*sin(2*pi*t/T). I use approximation with central finite difference of second order with second-order accuracy. It's it fpp(x) = ( f(x+h) -2f(x) + f(x-h) ) / h^2.... When i wrote simple program to prove that this approximation works, and it is:

clear, clc
% params of sin function
t = 0:0.01:1;
Ts = 0.01;
g1 = 0.6; T = 0.2;
% the second order differential of sin function
tpp = -4 * g1 * pi^2 * sin(2 * pi * t / T) / T^2;
% the second order difference of sin function
tdd = (sin(2 * pi * (t+Ts) / T) - 2*sin(2 * pi * t / T) + sin(2 * pi * (t-Ts) / T)) /Ts^2;
% plot the result
plot(t, t1dpp, '-b', t, t1dd, '-r')

Then I plotted the result the sins are different - with differential equation the Amp it (-600; 600) and with difference it's (-1000; 1000).
I'm new to difference equation i try to do my best, but i can't managed with this problem. Can someone help me ? I need the approximation to be same as the second derivative of sin function.
Thanks !
From: John D'Errico on
"Kiril " <kkirqkov(a)gmail.com> wrote in message <i073fn$g3n$1(a)fred.mathworks.com>...
> Hi folks, I have to use difference equation to find second derivative of sin function.
> This is the function g1*sin(2*pi*t/T). I use approximation with central finite difference of second order with second-order accuracy. It's it fpp(x) = ( f(x+h) -2f(x) + f(x-h) ) / h^2.... When i wrote simple program to prove that this approximation works, and it is:
>
> clear, clc
> % params of sin function
> t = 0:0.01:1;
> Ts = 0.01;
> g1 = 0.6; T = 0.2;
> % the second order differential of sin function
> tpp = -4 * g1 * pi^2 * sin(2 * pi * t / T) / T^2;
> % the second order difference of sin function
> tdd = (sin(2 * pi * (t+Ts) / T) - 2*sin(2 * pi * t / T) + sin(2 * pi * (t-Ts) / T)) /Ts^2;
> % plot the result
> plot(t, t1dpp, '-b', t, t1dd, '-r')
>
> Then I plotted the result the sins are different - with differential equation the Amp it (-600; 600) and with difference it's (-1000; 1000).
> I'm new to difference equation i try to do my best, but i can't managed with this problem. Can someone help me ? I need the approximation to be same as the second derivative of sin function.
> Thanks !

Perhaps this is a silly question on my part. But why
would you compute the derivative as tdd, but then
plot the variables t1ddp and t1dd?

> plot(t, t1dpp, '-b', t, t1dd, '-r')

Just a thought.

John
From: Kiril on
> > plot(t, t1dpp, '-b', t, t1dd, '-r')
Never mind this is copy line from my program and where is this "1" then i rote it here i miss it . So the line is
plot(t, tpp, '-b', t, tdd, '-r')
An for may be is stupid, but for me is not. An if it so stupid why don't help ?!!
From: Greg Heath on
On Jun 27, 4:52 am, "Kiril " <kkirq...(a)gmail.com> wrote:
> Hi folks, I have to use difference equation to find second derivative of sin function.
> This is the function g1*sin(2*pi*t/T). I use approximation with central finite difference of second order with second-order accuracy. It's it fpp(x) = ( f(x+h) -2f(x) + f(x-h) ) / h^2.... When i wrote simple program to prove that this approximation works, and it is:
>
> clear, clc
> % params of sin function
> t = 0:0.01:1;
> Ts = 0.01;
> g1 = 0.6; T = 0.2;
> % the second order differential of sin function  
> tpp  = -4 * g1 * pi^2 * sin(2 * pi * t / T) / T^2;
> % the second order difference of sin function
> tdd   = (sin(2 * pi * (t+Ts) / T) - 2*sin(2 * pi * t / T) + sin(2 * pi * (t-Ts) / T)) /Ts^2;
> % plot the result
> plot(t, t1dpp, '-b', t, t1dd, '-r')
>
> Then I plotted the result the sins are different - with differential equation the Amp it (-600; 600) and with difference it's (-1000; 1000).
> I'm new to difference equation i try to do my best, but i can't managed with this problem. Can someone help me ? I need the approximation to be same as the second derivative of sin function.
> Thanks !

What is 600/1000 ?

Greg
From: John D'Errico on
"Kiril " <kkirqkov(a)gmail.com> wrote in message <i075op$bs4$1(a)fred.mathworks.com>...
> > > plot(t, t1dpp, '-b', t, t1dd, '-r')
> Never mind this is copy line from my program and where is this "1" then i rote it here i miss it . So the line is
> plot(t, tpp, '-b', t, tdd, '-r')
> An for may be is stupid, but for me is not. An if it so stupid why don't help ?!!

I did help. I showed you that your code was in error,
and what mistake you apparently made.

How should I know that not only would you make
multiple mistakes, but that you don't even bother to
show us the actual code you used?

The crystal ball is so foggy. I simply cannot read your
mind.

But perhaps you might do as Greg suggests, and look
at the ratio of 600/1000. Does this tell you anything?
Perhaps if not, then you might look at the equations
you wrote down. Is there an error in there of that
magnitude?

John