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')
Show older comments
%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 Comment
Jan
on 17 Feb 2016
I've formatted your code. Please use the "{} Code" button.
Answers (1)
Walter Roberson
on 18 Feb 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');
Categories
Find more on Special Characters in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!