Octave least squares approximation [closed] - octave

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
So i've got a task.
That's here:
What values does the model F (t) = x(1) + x(2)*t^2 + x(3)*sin(π*t)
best fit in the least squares sense of the following data take place
at 1.0? t=[0.1 0.3 0.4 0.8 0.9] f=[2.06 2.91 3.19 3.16 2.89]
t=[0.1 0.3 0.4 0.8 0.9]';
f=[2.06 2.91 3.19 3.16 2.89]';
A=[ones(5,1),sin(pi*t)];
x=(A'*A)\(A'*f)
xx=linspace(0,1.0);
yy=x(1)+x(2).*xx.^2+x(3).*sin(pi.*xx);
figure; plot(t,f,'*',xx,yy)
I wrote this code and got an error
called from
code.m(example) at line 6 column 3

I think you can use pinv to solve x, i.e.,
m = [t.^0;t.^2;sin(pi*t)];
x = f*pinv(m);
such that
>> x
x =
1.5760 1.0504 1.5286
Data
t=[0.1 0.3 0.4 0.8 0.9];
f=[2.06 2.91 3.19 3.16 2.89];

Related

What to do if my model stucks ? Natural Language Processing Model [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 days ago.
Improve this question
I have been changing some params and adding layers and also standardization. But the mmodel seems to stuck at constant high accuracy after 1-2 epoch. Currently at 0.90 Acc both in train and val data.
Samples are heavily imbalanced, class proportion : 10:3:2.
I am using GRU as my model. as the code below :
# Using GRU
seed = 11
tf.keras.backend.clear_session()
np.random.seed(seed)
tf.random.set_seed(seed)
model = Sequential()
model.add(text_vectorization)
model.add(embedding)
model.add(GRU(32, return_sequences=True))
model.add(Dropout(0.5))
model.add(tf.keras.layers.BatchNormalization())
model.add(GRU(32))
model.add(Dropout(0.5))
model.add(tf.keras.layers.BatchNormalization())
model.add(Dense(3,activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics='accuracy')
model_gru = model.fit(X_train,y_train,epochs=20,validation_data=(X_test, y_test))
EXpected to have accuracy which is not constant after 1 or 2 epoch.

Octave - How to plot an "infinite"(= Defining the function on [0:35916] for me) sawtooth function [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I know how to plot a sawtooth function (thanks to another forum) but only on the domain [0:10] thanks to the following code which is actually working :
t=0:0.04:10;
A=1;
T=1;
rho= mod(t * A / T, A);
plot(t,rho)
A=the amplitude, T=the period,t=the time interval.
The problem is that I need the same function on the domain [0:35916] but when I try to adapt this code to do so (eg by extending the time interval), I get an error and I don't understand why.
error:
plt2vv: vector lengths must match error: called from plt>plt2vv at line 487 column 5 plt>plt2 at line 246 column 14 plt at line 113 column 17 plot at line 222 column 10
Simply modifying the original upper limit of your interval from 10 to 35916 should do the trick:
t=0:0.04:35916;
A=1;
T=1;
rho= mod(t * A / T, A);
plot(t,rho)
The code above yields the following image:
Of course it is up to you to adjust A and T to suit your needs.

How do I convert 234.35 into Binary? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I need to convert the above into Binary. I'm at a loss here.
Can you include full information on how you got the answer too?.
Step by step would be great!
First, convert the integral part which is 11101010. Next, you build the decimal part. If demonstrated informally, it is something like:
0.1 is one half, but 0.35 is less than that, so the first binary digit is zero -> .0 (0.35)
0.01 is one quarter, and 0.35 is greater than that, so then follows one. 0.35 minus one quarter is decimal 0.1 -> .01 (0.35 - 0.25 = 0.1)
0.001 is one eighth, and decimal 0.1 is less than that, so again zero -> .010 (0.1)
Next steps are: .0101 (0.1 - 0.0625 = 0.0375); .01011 (0.0375 - 0.03125 = 0.00625); then follow two zeroes, and we can probably cut it here.
So, the answer is 11101010.010110... As the original number has decimal part of 7/20, it becomes infinite when converted to binary.

function in Haskell that can solve an equation [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to write a function in Haskell that can solve the following problem(physic_problem):
What is the height (in a whole number of meters) of the shortest building that you could drop a ball from such that it would take at least 5 seconds to hit the ground?
The equation can be found here http://en.wikipedia.org/wiki/Equations_for_a_falling_body
I really tried hard on this and i need help!
Thank you so much!
Consider for instance this,
g :: Double
g = 9.81
dist :: Double -> Double
dist t = g * t^2 / 2
Then,
> dist 5
122.625
Additionally you may want to create a module out of the equations in that Wiki.
Update
For delivering an integral value consider for example
dist' :: (Integral a) => Double -> a
dist' t = ceiling $ g * t^2 / 2
Here we use ceiling (upper bound), yet note Converting to Integral for other rounding functions. Hence,
> dist' 5
123

ROUND IN SQL Works but for this case what to do in MYSQL [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to round the decimals like :
1.00 ->1.0
1.987->1.98
1.93-> 1.93
1.07->1.07
How to do this in mysql?
Here goes some documentation
http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_round
Quick answer:
mysql> SELECT ROUND(1.987, 2); = 1.99
OR More what you are looking for
truncate(1.987, 2) = 1.98
From Mysql decimal: floor instead of round
This only makes a difference if you are outputting the number (numerically, 1.0 = 1.00). So:
(case when format(num, 2) = '1.00' then '1.0' else format(num-0.005, 2) end)
The -0.005 is to overcome the fact that format() rounds rather than truncates.
Just like that:
SELECT if(NUMBER mod 1=0,ROUND(NUMBER,1),ROUND(NUMBER,2));
eg.
SELECT IF(1.00 MOD 1=0,ROUND(1.00,1),ROUND(1.00,2)); => 1.0
more info