Error using function fplot

조회 수: 10 (최근 30일)
Garrett Crawford
Garrett Crawford 2020년 5월 11일
댓글: Ameer Hamza 2020년 5월 11일
When typing my code, I keep getting the error of invalid parameter from fplot. Not sure why it keeps coming up. How would I fix this?
Code:
syms x
f(x) = log(x)^4 * exp((-x)^3) * x^2;
val = int(f(x),x,[0,Inf]);
vpa(val)
X = [0.5 : 0.1 : 2.5]
fplot(@(x) f(x),X,'b')
  댓글 수: 1
Geoff Hayes
Geoff Hayes 2020년 5월 11일
Garrett - what happens if you don't use a symbolic expression? From fplot 'f' input parameter, the first parameter is a function handle. Or, perhaps you can convert the f to a MATLAB function handle with matlabfunction.

댓글을 달려면 로그인하십시오.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 5월 11일
편집: Ameer Hamza 2020년 5월 11일
You need to specify range with two numbers.
syms x
f(x) = log(x)^4 * exp((-x)^3) * x^2;
val = int(f(x),x,[0,Inf]);
fplot(@(x) f(x), [0.5 2.5],'b')
  댓글 수: 2
Garrett Crawford
Garrett Crawford 2020년 5월 11일
The problem is to write a script to evaluate the integral f(x) = log(x)^4 * exp((-x)^3) * x^2;from x=0 to x=Infinity but to Also, plot x versesf(x),for x =[.5 : .1 : 2.5]. Would ths solution stil corelate with what was asked in the problem?
Ameer Hamza
Ameer Hamza 2020년 5월 11일
I think the above solution with fplot() should be acceptable in this case. But if you still want to plot at these specific x-values then you can use plot() instead of fplot. However, as you can see, the graph is not as smooth
syms x
f(x) = log(x)^4 * exp((-x)^3) * x^2;
val = int(f(x),x,[0,Inf]);
X = 0.5:0.1:2.5;
plot(X, f(X), 'b')

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by