I have made this Matlab program and I always get the same error when i try to ru
ID: 2073439 • Letter: I
Question
I have made this Matlab program and I always get the same error when i try to run it, what do i need to do.
Here is the program, and down below i will post the command Window.
classdef verkefni1
methods (Static)
function heimadami1
clf;
global A alpha
A=0.5;
alpha=1;
f=@(x) gefid_fall(x);
a=@(n) a_f(n);
b=@(n) b_f(n);
x=linspace(-3*pi,5*pi,1001);
y=f(x);
N1=2; y1=hlutsumma(a,b,x,N1);
N2=4; y2=hlutsumma(a,b,x,N2);
N3=8; y3=hlutsumma(a,b,x,N3);
figure(1)
plot(x,y,x,y1,x,y2,x,y3)
hold on
legend('y=f(x)=max(1-|x-1|/0.5,0)',['y=s_{'-int2str(N1) '}(x)'],...
['y=s_{' int2str(N2) '}(x)'],...
['y=s_{' int2str(N3) '}(x)'])
title('Fall f og hlutsummur Fourier-raðar þess')
axis([-10,16,-0.2,1.8])
end
end
methods
function y=hlutsumma(a,b,x,N)
M=length(x);
y=0.5*a(0)*ones(1,M);
for n=1:N
y=y+a(n)*cos(n*x)+b(n)*sin(n*x);
end
end
function y=gefid_fall(x)
global A alpha
y=max(1-abs(mod(x,2*pi)-alpha/A,O));
end
function y=a_f(n)
global A alpha
if n==0
y=A/pi;
else
y=2*cos(alpha*n)*(1-cos(A*n))/(pi*n^2*A);
end
end
end
end
Command Window
>> verkefni1
ans =
verkefni1 with no properties.
>>
How do I get the program to print out the graf/plot.
Thank you
Explanation / Answer
These are some changes required to be made to the code:
The matlab code is pasted below:
classdef verkefni1
methods (Static)
function heimadami1
clf;
global A alpha
A=0.5;
alpha=1;
f=@(x) verkefni1.gefid_fall(x);
a=@(n) verkefni1.a_f(n);
b=@(n) verkefni1.b_f(n);
x=linspace(-3*pi,5*pi,1001);
y=f(x);
N1=2; y1=verkefni1.hlutsumma(a,b,x,N1);
N2=4; y2=verkefni1.hlutsumma(a,b,x,N2);
N3=8; y3=verkefni1.hlutsumma(a,b,x,N3);
figure(1)
plot(x,y,x,y1,x,y2,x,y3)
hold on
legend('y=f(x)=max(1-|x-1|/0.5,0)',['y=s_{'-int2str(N1) '}(x)'],...
['y=s_{' int2str(N2) '}(x)'],...
['y=s_{' int2str(N3) '}(x)'])
title('Fall f og hlutsummur Fourier-raðar þess')
axis([-10,16,-0.2,1.8])
end
end
methods (Static)
function y=hlutsumma(a,b,x,N)
M=length(x);
y=0.5*a(0)*ones(1,M);
for n=1:N
y=y+a(n)*cos(n*x)+b(n)*sin(n*x);
end
end
function y=gefid_fall(x)
global A alpha
y=max(1-abs(mod(x,2*pi)-alpha/A),0);
end
function y=a_f(n)
global A alpha
if n==0
y=A/pi;
else
y=2*cos(alpha*n)*(1-cos(A*n))/(pi*n^2*A);
end
end
function y=b_f(n)
global A alpha
if n==0
y=A/pi;
else
y=2*cos(alpha*n)*(1-cos(A*n))/(pi*n^2*A);
end
end
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.