- #1
- 18
- 0
I have some problems on 'for' and 'while' loop so I could not write a matlab program for this question;
.
Well, how can I start?
Well, how can I start?
function y = f(x)
%%The loop would look like:
y=0.0;
for n = 1:50
y = y + 2(-1)^(n+1) ( (pi^2)/n - (6/(n^3)) sin(n x);
end
%%After which you could write
x = 1.0 : 0.1 : 2*pi
y = f(x);
plot(y,x)
L = 8;
syms n x;
a_n = sqrt(2/L)*( (2*L)/(n*pi) )*( (sin((n*pi)/2))^2 )*sin(n*pi); %fourier coefficient a_n
b_n = -sqrt(2/L)*( (2*L)/(n*pi) )*( (sin((n*pi)/2))^2 )*cos(n*pi); %fourier coefficient b_n
x = 0:0.2:8; %range
V_x = symsum( a_n*sqrt(2/L)*cos( (n*2*pi*x)/L ) + b_n*sqrt(2/L)*sin( (n*2*pi*x)/L ), n, 1, 9 ); %fourier series
plot(x, V_x);
grid on;
axis([ 0 8 -1.4 1.4]);
hold on;