Problem with Matlab example

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

Problem with Matlab example

Postby nachovetm » Wed Jun 18, 2008 3:15 pm

This is my problem:

Create a function for this:

Image

n= 1, 2, 3, 5, and 10 each time.

x= -pi to pi (with 100 values)


I made this:

SERIE.M
function f=serie(x,n)
f=1;
for i=1:n
f=f+((-1)^n * x.^(2*n)) / (prod([1:2*n]));
end

TP.M
x=linspace(-pi,pi,100);
n=[1, 2, 3, 5, 10];
fcos=cos(x);
for i=1:length(n)
n(i)
pause
y(i)=serie(x,n(i))
pause
errora(i)=abs(fcos-y(i))
pause
errorr(i)=errora(i)./fcos
pause
end
end

When I run that, an error appear:
??? In an assignment A(I) = B, the number of elements in B and
I must be the same.

Error in ==> TP.M
On line 7 ==> y(i)=serie(x,n(i))


Thanks if you can help me.
I use MATLAB 6.5 r13
nachovetm
 
Posts: 1
Joined: Wed Jun 18, 2008 2:49 pm

Return to Dynare help

Who is online

Users browsing this forum: No registered users and 6 guests