Function to display polynomial based on user input

조회 수: 8 (최근 30일)
Mitchell
Mitchell 2019년 3월 1일
편집: Mitchell 2019년 3월 1일
function polynom3 ()
%This function outputs a third-order polynomial function with coefficients
%as the input variables
w=input('cubed term \n');
x=input('squared term \n');
y2=input('x-term \n');
z=input('constant term one \n');
z2=input('constant term two \n');
z3=input('constant term three \n');
z4=input('constant term fourb \n ');
fprintf('y=%d(z).^%d(w)+%d(z2).^%d(x)+%d(z3).^%d(y2)+%d(z4)\n',w,x,y2,z,z2,z3,z4)
I'm wanting a 3rd degree polynomial but it out puts wrong
this is what it is outputting:
y=(1(z).^2(w))+(3(z2).^4(x))+(5(z3).^6(y2))+(7(z4))
How do I get it to display as a regular ploynomial function

채택된 답변

Geoff Hayes
Geoff Hayes 2019년 3월 1일
MItchell - I think that you are confusing some of your variables as exponents. Wouldn't the code be more like
fprintf('y=%d(x)^3 + %d(x)^2 + %d(x) + %d + %d + %d + %d)\n',w,x,y2,z,z2,z3,z4)
I may be misunderstanding what your inputs are supposed to represent - you may want to rename them differently and/or organize the data in a different manner.
  댓글 수: 1
Mitchell
Mitchell 2019년 3월 1일
편집: Mitchell 2019년 3월 1일
Thank you for pointing that out!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by