How can I use the array of data into a formula to calculate and get the data.

11 ビュー (過去 30 日間)
Aung Moe Zaw
Aung Moe Zaw 2022 年 3 月 30 日
コメント済み: Aung Moe Zaw 2022 年 3 月 30 日
My code is used to produce a wave (y(:,1)) and I want to use that data into a formula Vout.
function [] = call_spring()
t = 0:0.001:5;
y0 = [0, 0];
x1 = 25*cos(4*pi*t);
[t, y] = ode45(@spring, t, y0);
plot(t, y(:,1), t, x1,'-r');
f=50;
Ip=12/10000;
Np=400;
Ns=200;
r=2;
x=y(:,1);
u0=4*pi*(10^-7);
b=320;
m=160;
Vout=f*Ip*((4*pi*Np*Ns*u0*b*x)/(3*m*log(r)))*(1-((x^2) / (2*b^2)))
end
function dzdt = spring(t, y)
k = 342;
m = 2.853;
x1 = 25*cos(4*pi*t);
y1 = y(1);
y2 = y(2);
dzdt = [y2;
(-k/m)*(y1-x1)];
end

採用された回答

Sam Chak
Sam Chak 2022 年 3 月 30 日
編集済み: Sam Chak 2022 年 3 月 30 日
Please check if the following results are expected.
function [] = call_spring()
t = 0:0.001:5;
y0 = [0, 0];
x1 = 2.5*cos(4*pi*t);
[t, y] = ode45(@spring, t, y0);
figure(1)
plot(t, y(:,1), t, x1)
grid on
xlabel('Time, t')
ylabel('y_{1} and x_{1}')
title('Time response of y_{1}, perturbed by x_{1}')
legend('y_{1}', 'x_{1}')
f = 50;
Ip = 12/10000;
Np = 400;
Ns = 200;
r = 2;
x = y(:,1);
u0 = 4*pi*1e-7;
b = 320;
m = 160;
Vout = f*Ip*((4*pi*Np*Ns*u0*b*x)/(3*m*log(r))).*(1-((x.^2)/(2*b^2)));
figure(2)
plot(t, Vout)
grid on
xlabel('Time, t')
ylabel('Vout')
title('Time response of Vout')
end
function dzdt = spring(t, y)
k = 342;
m = 2.853;
x1 = 2.5*cos(4*pi*t);
y1 = y(1);
y2 = y(2);
dzdt = [y2;
(-k/m)*(y1 - x1)];
end
Results:

その他の回答 (1 件)

Mathieu NOE
Mathieu NOE 2022 年 3 月 30 日
編集済み: Mathieu NOE 2022 年 3 月 30 日
hello
some dots where missing here (read again the doc about dot product)
Vout=f*Ip*((4*pi*Np*Ns*u0*b*x)./(3*m*log(r))).*(1-((x.^2) / (2*b^2)));

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by