필터 지우기
필터 지우기

Method to plug in a value

조회 수: 13 (최근 30일)
Aaron Atkinson
Aaron Atkinson 2020년 3월 1일
답변: Arramis 2024년 1월 21일
I am currently working on a bracketing algorithem (specifically false position for finding roots).
My issue is that the equation will be imputed as ways such as (x+(4*x^8)).
I need to be able to plug in the variables x_i and x_u into that equation as a susbtitute for x?
What would be the primary way I should go about doing this in a loop?
  댓글 수: 1
dpb
dpb 2020년 3월 1일
W/o seeing far more of code I'd guess just write an anonymous function and call it with the desired input...
fnF=@(x) x+4*x.^8;
If it's always some form of a polynomial, one could also just set the coefficients vector and call polyval
b=[4 0 0 0 0 0 0 1 0]; % 4x^8 + x
F=polyval(b,x);

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

채택된 답변

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020년 3월 1일
I would agree with dpb that the best way is to use anonymous functions, the only thing that you additionally need is to be able to convert the user input to the function. A way to do it is with the eval function:
Equation = 'x+4*x.^8';
fnF= eval(['@(x)',Equation])
fnF =
function_handle with value:
@(x)x+4*x.^8

추가 답변 (1개)

Arramis
Arramis 2024년 1월 21일
how to enter and into mat lab as the equation u=x+y

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by