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

조회 수: 11 (최근 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 CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by