matlab Fit the third polynominal
Mostrar comentarios más antiguos
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 comentarios
dpb
el 4 de Dic. de 2020
See
doc polyfit
and friends...
Nora Tarek
el 4 de Dic. de 2020
Matt J
el 4 de Dic. de 2020
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
el 4 de Dic. de 2020
Editada: Nora Tarek
el 4 de Dic. de 2020
Steven Lord
el 4 de Dic. de 2020
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
el 4 de Dic. de 2020
" 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
el 4 de Dic. de 2020
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."
Respuesta aceptada
Más respuestas (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 comentario
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);
>>
Categorías
Más información sobre Resizing and Reshaping Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!