Error in Function ?
1 回表示 (過去 30 日間)
古いコメントを表示
naresh bhimchand
2019 年 12 月 17 日
コメント済み: naresh bhimchand
2019 年 12 月 18 日
[t,v] = ode45(@velocity, [10 1], [22.5])
plot(t,c)
function f = velocity(t,v)
f = 8*v/t
M = [4 5;5 6]
K = [23 45;67 54]
[X e] = polyeig(K,M)
F = [32+f;32+f]
wn = 3221.3;
zeta = 0.061;
wd = 3254.4;
Fn = X.'*F
Fnn = Fn(2,1)
g = -wd.^2*sin(wd*t) - 2*wd*zeta*wn*cos(wd*t) +zeta.^2*wn.^2*sin(wd*t)
a = Fnn.*(cos(-zeta*wd*t)+sin(-zeta*wd*t))/(8*wd.^2 +1i*2.12*wd+253)
c = a.*g
end
From the above code I am getting this error" Data must be numeric, datetime, duration or an array convertible to double". so,help me to plot t with c .Thank you in advance.
0 件のコメント
採用された回答
Walter Roberson
2019 年 12 月 17 日
編集済み: Walter Roberson
2019 年 12 月 17 日
plot(t,c)
You are not storing into c in the workspace that you are doing the ode45 call, so it will have whatever value it had before the call.
function f = velocity(t,v)
f = 8*v/t
M = [4 5;5 6]
K = [23 45;67 54]
[X e] = polyeig(K,M)
F = [32+f;32+f]
wn = 3221.3;
zeta = 0.061;
wd = 3254.4;
Fn = X.'*F
Fnn = Fn(2,1)
g = -wd.^2*sin(wd*t) - 2*wd*zeta*wn*cos(wd*t) +zeta.^2*wn.^2*sin(wd*t)
a = Fnn.*(cos(-zeta*wd*t)+sin(-zeta*wd*t))/(8*wd.^2 +1i*2.12*wd+253)
c = a.*g
end
The only line there that affects the ode45 integration is the very first one, f = 8*v/t . All of the rest are wasted computation as far as ode45 is concerned.
I would suggest,
[t,v] = ode45(@velocity, [10 1], [22.5]);
c = arrayfun(@calc_c, t, v);
plot(t, c);
function f = velocity(t,v)
f = 8*v/t;
end
function c = calc_c(t,v)
f = 8*v/t;
M = [4 5;5 6];
K = [23 45;67 54];
[X e] = polyeig(K,M);
F = [32+f;32+f];
wn = 3221.3;
zeta = 0.061;
wd = 3254.4;
Fn = X.'*F;
Fnn = Fn(2,1);
g = -wd.^2*sin(wd*t) - 2*wd*zeta*wn*cos(wd*t) +zeta.^2*wn.^2*sin(wd*t);
a = Fnn.*(cos(-zeta*wd*t)+sin(-zeta*wd*t))/(8*wd.^2 +1i*2.12*wd+253);
c = a.*g;
end
4 件のコメント
Steven Lord
2019 年 12 月 18 日
You can't get from 10 to 0 by taking steps of length 0.0001.
You can get from 10 to 0 by taking steps of length -0.0001.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!