How can I define these on matlab?

조회 수: 1 (최근 30일)
ilyada
ilyada 2018년 4월 22일
답변: Benjamin Großmann 2018년 5월 22일

I have a math function like f(x)=(x-4)* (x-6)^3 * (x-1)^2

and I define it like this;

f= @(x) (x-4)*(x-6)^3*(x-1)^2;
xlow=0;
xmid=32;
xhi=40;

And I want to define f(xlow), f(xmid), and f(xhi) but I couldn't. Also I have to define these s(low), s(mid), and s(hi) but when I tried I got error warning so I failed.

s(low) = (xlow)^2;
s(mid) = (xmid)^2;
s(hi) = (xhi)^2;

I tried to define them to use in a formula which is:

xqu= f(low)*(s(mid) - s(hi))+fx(mid)*(s(hi)-s(low) +f(hi)*(s(low)-s(mid))) / 2*(f(low)*(xmid-xhi)+fx(mid)*(xhi-xlow)+f(hi)*(xlow-xmid));

but again I got warning and I couldn't do that either.

답변 (1개)

Benjamin Großmann
Benjamin Großmann 2018년 5월 22일
When f is a function, then you can not "define" something like
f(low) = ...
because the stuff in brackets is passed to the function f as argument. You can use f(low) inside a formula because the functions return value is then used inside your formula. It is possible to define
flow = f(low);
and afterwards use flow inside the formula same for s(mid) ....:
f= @(x) (x-4)*(x-6)^3*(x-1)^2;
xlow=0;
xmid=32;
xhi=40;
flow = f(xlow);
fmid = f(xmid);
fhi = f(xhi);
xqu= f(low)*(smid...

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by