Trying to get this code to work but I am getting this error code (Error using plot A numeric or double convertible argument is expected), ( Error in Lab6 (line 8) plot(n,H,'r')
Afficher commentaires plus anciens
%Harmonic function for H(n)
title('Harmonic Function')
xlabel('values of n 1<=n<=100')
ylabel('Harmonic Function H(n)')
for n = 1:100
syms H(n)
H(n) = harmonic(n);
plot(n,H,'r')
end
%Harmonic function for ln n
title('Harmonic Function for log(n)')
xlabel('values of n')
ylabel('Harmonic Function log(n)')
for n = 1:100
syms f(n)
f(n) = log(n);
y = harmonic(f);
plot(n,y,'--','k')
end
%Harmonic function for 1+ln n
title('Harmonic Function')
xlabel('values of n')
ylabel('Harmonic function 1+log(n)')
for n = 1:100
syms f(n)
f(n) = 1+log(n);
y = harmonic(f);
plot(n,y,'--','k')
end
1 commentaire
Jan
le 17 Fév 2016
I've formatted your code. Please use the "{} Code" button.
Réponses (1)
Walter Roberson
le 18 Fév 2016
MATLAB cannot plot symbolic formula.
H = zeros(1,100);
yL = zeros(1,100);
yL1 = zeros(1,100);
N = 1 : 100;
for n = N
H(n) = double( harmonic(sym(n)) );
yL(n) = double( harmonic( log(sym(n)) ) );
yL1(n) = double( harmonic( 1 + log(sym(n)) ) );
end
plot(N, H, 'r', N, yL, '--k', N, yL1, ':g');
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!