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

11 views (last 30 days)
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

Accepted Answer

Sam Chak
Sam Chak on 30 Mar 2022
Edited: Sam Chak on 30 Mar 2022
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:

More Answers (1)

Mathieu NOE
Mathieu NOE on 30 Mar 2022
Edited: Mathieu NOE on 30 Mar 2022
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)));

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!