I am new to matlab and do not know how to make a table that compares the values of this polynomial function with w=1/(x^2+1)
my attempt
x= [-5,-3,-1, 1, 3,5]
x =
-5 -3 -1 1 3 5
y= [0.0385, 0.10, 0.50, 0.50, 0.10, 0.0385]
y =
0.0385 0.1000 0.5000 0.5000 0.1000 0.0385
yp=[0.0148,0.06,0.50,-0.50,-0.6,-0.0148]
yp =
0.0148 0.0600 0.5000 -0.5000 -0.6000 -0.0148
hp = hermite (x, y, yp )
hp =
-0.0000 -0.0000 0.0001 0.0004 -0.0011 -0.0100 0.0072 0.0969 -0.0113 -0.4156 0.0051 0.8282
Now it only remains to compare in a table the values of hp with w.
Could someone please help me?
Thanks for your help
I see no
win your question, but in general the expressionwill, if the vectors have the same length, return a vector of
0s and1s, of that length, representing the cases where the two vectors match (1) or don’t match (0). In passing, note that comparison for equality of floating-point numbers is fraught with ‘issues’ and you might be better evaluating:replacing
10^-6by your preferred tolerance.Given your definition for
wyou should be able to writeNote the use of the elementwise squaring operator
.^, which returns a vector of the same length asxwith each element the square of the corresponding element inx. Of course, the expressionwill return a vector of the differences, which might be what you want.