How to calculate r squared from a given cos regression model

1 view (last 30 days)
Hi i am a new learner, i got confused how can i calculate like this,
if there's two sets,
x = [0.0000 0.5236 1.0472 1.5708 2.0944 2.6180 3.1416]
y = [2.7600 -2.3902 1.3800 0.0000 -1.3800 2.3902 -2.7600]
and the given function, y = a cos(5x), find the r squared for this function

Accepted Answer

Rik
Rik on 16 Mar 2020
y_fit = a cos(5*x)
err=y-y_fit;
SSres=sum(err.^2);
SStot=sum((y-mean(y)).^2);
rsq=1-(SSres./SStot);
  5 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Linear and Nonlinear Regression in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!