Code to input function
조회 수: 2 (최근 30일)
이전 댓글 표시
I want to make a code where user can input the the function and as the output they get plot of f(x) vs x and also the roots of that non linear equation.
댓글 수: 0
답변 (2개)
David Hill
2022년 8월 29일
Plotting would not be a problem, but finding all the roots is a problem. Recommend looking at fzero
a=input('Function (example: @(x)x.*cos(x)-x.^2.*sin(x)+exp(-x)): ','s');
f=str2func(a);
x=-pi:.001:2*pi;
plot(x,f(x));
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!