필터 지우기
필터 지우기

How to find the value of a function for different input?

조회 수: 53 (최근 30일)
Sumit dash
Sumit dash 2020년 2월 5일
편집: KSSV 2020년 2월 5일
hello !
lets say i have a function f(x)=x^2+3*x;
i want to find the function vaslues from x=1 to x=20.
how to write the code for the above ?
syms x
f=x^2+3*x;
for i=1:20
f(i);
end
above code is showing error. please provide your input !

답변 (1개)

KSSV
KSSV 2020년 2월 5일
편집: KSSV 2020년 2월 5일
Multiple methods:
Method # 1 Anonymous functions
f = @(x) x.^2+3*x ;
x = linspace(1,20,100) ;
y = f(x) ;
plot(x,y)
Method # 2 Using arrays
x = linspace(1,20,100) ;
y = x.^2+3*x ;
plot(x,y)
Method # 3 using syms
syms x
f(x) = x^2+3*x ;
double(f(3))

카테고리

Help CenterFile Exchange에서 Formula Manipulation and Simplification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by