matlab Fit the third polynominal
이전 댓글 표시
this is my code
n=3;
A=zeros(n+1,n+1);
B= zeros (n+1,1);
a=zeros (n+1,1);
for row=1 :n+1
for col=1 :n+1
if row ==1 &&col==1
A(row,col)== m;
continue
end
A(row,col)= sum (x.^(row+col-2));
end
B(row)= sum(x.^(row-1).*y);
end
a =A\B
end
end
from here I want the user to input a number thisnumber musnot be less than the values exsist in Y and when this user enter the number m the four points that my program will do to fit the third degree polynomial the user entered number must be between them ( so two points before my number and two points after )
댓글 수: 7
dpb
2020년 12월 4일
See
doc polyfit
and friends...
Nora Tarek
2020년 12월 4일
Matt J
2020년 12월 4일
OK, but what is your question? Is something not working? One problem I see immediately is this expression,
elseif 10.042<H<18.3935
It should really be,
elseif 10.042<H & H<18.3935
Nora Tarek
2020년 12월 4일
편집: Nora Tarek
2020년 12월 4일
Steven Lord
2020년 12월 4일
In addition to what Matt J noted you have another similar problem.
if H>18.3935 && H<10.0427
Can you give me an example of a number that is simultaneously greater than 18 and less than 10?
dpb
2020년 12월 4일
" donot want to use polyfit"
Why in the world not? It's much simpler and uses the same internals as does backslash.
"my program will do to fit the third degree polynomial the user entered number must be between them ( so two points before my number and two points after ) "
What if the user enters 5.3, say?
HINT:
doc interp1 % Use backwards of normal for inverse lookup with 'next' or 'previous' method
Steven Lord
2020년 12월 4일
Why in the world not? It's much simpler and uses the same internals as does backslash.
I'm 95% sure the answer is "because it's a homework assignment."
채택된 답변
추가 답변 (1개)
I'm guessing something on the lines of the following would be about the ticket...
nProp=listdlg('ListString',{'Ultimate strength', 'Toughness', 'Young''s modulus'}, ...
'Name','MATERIAL PROPERTIES','PromptString', ...
'Select Desired Properties', ...
'SelectionMode','single', ...
'ListSize',[150 150]);
switch nProp
case 1
x=[0,12.5,25,37.5,50,62.5,75,87.5,100];
y=[10.0427, 10.3969,10.9316,11.5673,12.3015,13.1827,14.5476,16.0764,18.3935];
xmin=min(x); xmax=max(x);
ymin=min(y); ymax=max(y);
H=input("Enter the Independent Variable Value between " +xmin+ " and " +xmax+ ": ");
if ~iswithin(H,xmin,xmax)
error("Enter a value between " +xmin+ " and " +xmax)
end
PropVal=interp1(x,y,H,'pchip');
case 2
....
end
I didn't handle the error; just abort and also made the presumption that it is really x and not y that is the independent variable -- using descriptive variable names would go a long way towards helping be able understand the code intent.
One could use a slider or other input technique to bound the input to be much less user beligerent than just input
댓글 수: 1
Oh. iswithin is my handy-dandy utility routine
>> type iswithin
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
>>
카테고리
도움말 센터 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!