Cannot get the function to draw function

3 views (last 30 days)
Martin Placek
Martin Placek on 2 Dec 2020
Answered: Steven Lord on 2 Dec 2020
Hello, so we are doing a Fouriers series and we got a script from the teacher to work with. My friends which have different functions to draw made them work, but i for some reason cannot. It gets stuck right at the beginning, so heres the code:
syms t k
T = 6;
w = 2*pi/T;
f1 = exp(-3*t)-2;
f2 = 0;
T1 = 5;
%n = 3;
m = 10;
%----------------------------------------------------------------------------
%Just making sure its calculable
I = int(f1^2,t,0,T1)+ int(f2^2,t,T1,T)
vpa(I)
if I == Inf
error('Not calculable.')
else
fprintf('calculable')
end
%----------------------------------------------------------------------------
%Your function
t1 = 0: 1/10000 : 5;
funkce1 = exp(-3*t)-2;
t2 = 5 :1/10000: 6;
funkce2 = 0*ones(size(t2));
figure(1)
set(gcf,'color','w');
plot(t1, funkce1, 'k', t2, funkce2, 'k')
xlabel('t');
ylabel('f(t)');
title('Zadaná funkce')
grid on
hold on
ylim([-2.5 1.5]);
plot(0,1,'ok', 'MarkerFaceColor','k')
plot(pi/2,1,'ok', 'MarkerFaceColor','k')
plot(pi/2,2,'ok')
plot((3/2)*pi,2,'ok')
The last few bits are left from the teachers version. The error it says to me is: Error using plot
Data must be numeric, datetime, duration or an array convertible to double.

Answers (2)

Martin Placek
Martin Placek on 2 Dec 2020
Just to be clear, this is just the part of a code that allows us to plot the function we are supposed to make. Mine is the e function in the f1, it goes from 0 to 6, and then theres a constant 0 from 5 to 6

Steven Lord
Steven Lord on 2 Dec 2020
% t1 = 0: 1/10000 : 5;
% funkce1 = exp(-3*t)-2;
Is funkce1 supposed to use t or t1? I could see it using the symbolic variable t if you wanted to use fplot not plot:
syms t
funkce1_sym = exp(-3*t)-2;
fplot(funkce1_sym, [0 5])
But if you want to plot it numerically:
figure
t1 = 0: 1/10000 : 5;
funkce1_num = exp(-3*t1)-2;
plot(t1, funkce1_num)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!