Error in Function ?

4 visualizzazioni (ultimi 30 giorni)
naresh bhimchand
naresh bhimchand il 17 Dic 2019
Commentato: naresh bhimchand il 18 Dic 2019
[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.

Risposta accettata

Walter Roberson
Walter Roberson il 17 Dic 2019
Modificato: Walter Roberson il 17 Dic 2019
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 Commenti
Steven Lord
Steven Lord il 18 Dic 2019
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.
naresh bhimchand
naresh bhimchand il 18 Dic 2019
Sorry my mistake.Thanks,bro.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by