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')

1 次查看(过去 30 天)
%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 个)

Walter Roberson
Walter Roberson 2016-2-18
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');

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by