Cannot get the function to draw function
Afficher commentaires plus anciens
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.
Réponses (2)
Martin Placek
le 2 Déc 2020
0 votes
% 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)
Catégories
En savoir plus sur Calculus dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

