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
dpb 2020년 12월 4일
See
doc polyfit
and friends...
Nora Tarek
Nora Tarek 2020년 12월 4일
i donot want to use polyfit
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
Nora Tarek 2020년 12월 4일
편집: Nora Tarek 2020년 12월 4일
i cannot make it take the user input data H and find the four points that the code will use to fit the third degree ploynominal like if the use entered 14 which is a number between the points in y
then the four points that we should use is(50,12.3015) and (62.5, 13.1827) and (75, 14.5476)and ( 87.5 ,16.0764) to fit the third degree polynominal
However if it chose outside the range of Y there will be a message that what he entered is invalid
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
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
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."

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

 채택된 답변

Matt J
Matt J 2020년 12월 4일

0 개 추천

This might be what you want:
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];
ymin=min(y);
ymax=max(y);
Method=input('Input the physical propety you want , Ultimate strenght (1), Toughness (2), Young’s modulus (3): ');
if Method==1
disp('Enter parameters');
H=input('enter the number you want ');
if ~(H>ymin & H<ymax)
disp ( "Enter a value between " +ymin+ " and " +ymax)
else
a=polyfit(x,y,3);
end
end

댓글 수: 1

dpb
dpb 2020년 12월 4일
That doesn't select the set of points bracketing the user input for the specific fit the OP is looking for.
Probably a better and certainly easier to code. I'd suggest would be to use interp1 with 'pchip' method.

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

추가 답변 (1개)

dpb
dpb 2020년 12월 4일
편집: dpb 2020년 12월 4일

0 개 추천

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

dpb
dpb 2020년 12월 4일
편집: dpb 2020년 12월 4일
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에 대해 자세히 알아보기

질문:

2020년 12월 4일

편집:

dpb
2020년 12월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by