How to do "Cosine wave approximation“ for random plot data

I want to do "Cosine wave approximation“ for randam plot data.
Is there a way to forcefully approximate the following data?
Also please tell me about how to do it.
x = [0.087266463 0.261799388 0.436332313 0.610865238 0.785398163 0.959931089 1.134464014 1.308996939 1.483529864];
y = [22 22 16 13 13 9 3 0 3];

 Réponse acceptée

easy peasy. Though I have no clue what it means to "forcef\ully approximate".
x0 = [mean(y),max(y) - min(y)/2,0,3];
ft = fittype('a + b*cos((x-c)*d)')
ft =
General model:
ft(a,b,c,d,x) = a + b*cos((x-c)*d)
mdl = fit(x',y',ft,'startpoint',x0)
mdl =
General model:
mdl(x) = a + b*cos((x-c)*d)
Coefficients (with 95% confidence bounds):
a = 11.96 (7.416, 16.51)
b = 10.43 (4.97, 15.88)
c = -0.02594 (-0.8867, 0.8348)
d = 2.079 (0.141, 4.017)
plot(x,y,'o'),hold on,plot(mdl)
untitled.jpg

5 commentaires

Also, can we approximate all plots with sin waves in the following range
y=Asin(x+B),π/4≦x≦π/2
The answer to your question would be yes, you can, although you might be less than pleased with the result because the model you pose will be inadequate. Regardless, why not try it? What stops you from reading my example, then trying to do so yourself?
clear;clc;
x = [0.087266463 0.261799388 0.436332313 0.610865238 0.785398163 0.959931089 1.134464014 1.308996939 1.483529864];
y = [22 22 16 13 13 9 3 0 3];
x0 = [mean(y),max(y) - min(y)/2,0,3];
ft = fittype('a + b*cos((x-c)*d)')
ft =
General model:
ft(a,b,c,d,x) = a + b*cos((x-c)*d)
mdl = fit(x',y',ft,'startpoint',x0)
mdl =
General model:
mdl(x) = a + b*cos((x-c)*d)
Coefficients (with 95% confidence bounds):
a = 11.96 (7.416, 16.51)
b = 10.43 (4.97, 15.88)
c = -0.02594 (-0.8867, 0.8348)
d = 2.079 (0.141, 4.017)
plot(x,y,'o'),hold on,plot(mdl)
エラー: ファイル: file.m 行:6 列:6
式が無効です。不足している文字または余分な文字をチェックしてください。
頂いたプログラムを試したところ以上のエラーが発生してしまいました.
また,sin近似を試そうとcosの部分をsinに書き換え,範囲を指定して行ったのですが,解析が回らなかったので質問させていただいた手前でございます.
clear;clc;
x = [0.087266463 0.261799388 0.436332313 0.610865238 0.785398163 0.959931089 1.134464014 1.308996939 1.483529864];
y = [22 22 16 13 13 9 3 0 3];
x0 = [mean(y),max(y) - min(y)/2,0,3];
ft = fittype('a + b*sin((x-c)*d)')
ft =
General model:
ft(a,b,c,d,x) = a + b*sin((x-c)*d)
mdl = fit(x',y',ft,'startpoint',x0)
mdl =
General model:
mdl(x) = a + b*sin((x-c)*d)
k=(x-c)*d
klim=([pi/4 pi/2])
Coefficients (with 95% confidence bounds):
a = 11.96 (7.416, 16.51)
b = 10.43 (4.97, 15.88)
c = -0.02594 (-0.8867, 0.8348)
d = 2.079 (0.141, 4.017)
plot(x,y,'o'),hold on,plot(mdl)
エラー: ファイル: file.m 行:6 列:6
式が無効です。不足している文字または余分な文字をチェックしてください。
matlabを頻繁に触らないためx0の部分で何を設定しているかもわからない現状です. Coefficients (with 95% confidence bounds):以下の各数値も何を入れてるか理解できません.
If I had to guess, you are trying to execute lines of command window output from the curve fitting toolbox.
I would strongly suggest that you read the documentation for the curve fitting toolbox. It also looks like you want to read the getting started tutorialsin MATLAB, since it looks like you are trying to execute things that are not MATLAB code.
カーブフィッティングツールをインストールし,理解することができあました.
また,当初の課題も解決いたしました.
ご丁寧にありがとうございました.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by