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 件のコメント
回答 (1 件)
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');
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!