modify code for polynomial function

i try to modify this code but can't pass .please help with proper code
function fh = poly_fun(p)
function polynomial = poly(x)
polynomial = 0;
ii = 1:length(p)
polynomial = polynomial + p(ii).*x.^(ii-1);
end
fh = @poly;
end

댓글 수: 2

Rik
Rik 2020년 9월 8일
Unforturnately for Mohaiminul Islam Google cache takes some time to update, so the evidence of his attempt to cheat is foiled. A permalink to what he posted can be found here (will take a few hours to become available).
Removing your question after receiving an answer and help is extremely rude. It is also pointless, because of comments like this enable your teacher to find your post, and because site admins can often restore your edit.
Rena Berman
Rena Berman 2020년 10월 9일
(Answers Dev) Restored edit

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

답변 (1개)

KSSV
KSSV 2020년 9월 7일
편집: KSSV 2020년 9월 8일

0 개 추천

n = length(p)-1 ; % degree of polynomial
val = sum(p.*(x.^(n:-1:0)))

댓글 수: 11

Walter Roberson
Walter Roberson 2020년 9월 7일
sum(val)
Walter Roberson
Walter Roberson 2020년 9월 7일
You do not tell us what the requirements are, so we cannot tell you whether the code is correct or not.
I would point out that you have no assignments inside your function poly(), and in particular do not assign to your left hand side, polynomial
Walter Roberson
Walter Roberson 2020년 9월 7일
Notice that the sample code assigns to polynomial within function poly. Your code based upon KSSV's suggestion does not assign to polynomial within function poly.
Mohaiminul Islam
Mohaiminul Islam 2020년 9월 7일
@walter roberson could you help me please with the proper code to pass ? Thanks in Advance
Walter Roberson
Walter Roberson 2020년 9월 7일
You need to assign to polynomial within the function poly
The internal function needs to accept a location to evaluate the polynomial at, and needs to return the value of the polynomial evaluated there.
sum(polynomial) is not being assigned to any variable, and it has no semi-colon after the end of it. MATLAB is going to compute the value and then display it, but is not going to assign the result to anything. The effect is the same as
disp(sum(polynomial))
Mohaiminul Islam
Mohaiminul Islam 2020년 9월 7일
so can tell me how to solve this ?
Walter Roberson
Walter Roberson 2020년 9월 8일
You are not asked to display the sum of the polynomial. Therefore there are two possibilities that you will need to decide between:
  1. Delete the line sum(polynomial) as not contributing anything to what you are returning from the function; or
  2. Assign the result of sum(polynomial) to something.
Reminder:
The internal function needs to accept a location to evaluate the polynomial at, and needs to return the value of the polynomial evaluated there.
Mohaiminul Islam
Mohaiminul Islam 2020년 9월 8일
Thanks for helping. can't understand anything . just gonna skip this assignment . :)
KSSV
KSSV 2020년 9월 8일
There should be sum. I missed it and Walter Roberson pointed it. Hat's off to Walter Roberson for your patience.
Mohaiminul Islam
Mohaiminul Islam 2020년 9월 8일
@walter roberson
Thanks for helping and show me the path
did some silly mistake . just passed the assignment

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

카테고리

도움말 센터File Exchange에서 Polynomials에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2020년 9월 7일

댓글:

2020년 10월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by