My matlab code is only returning first output
Show older comments
So my code here is only returning the first ouput voltage and is also saving it as ans in workshop instead of voltage, I want it to return all three outputs by their name and save them into workshop but I can't figure out what's wrong?
function [voltage, current, evarde] = kretsen2;
U0 = 220;
U = U0;
I0 = 0;
I = I0;
u0 = [I0;U0];
u = u0;
C = 0.5*(10^-6);
L0 = 0.7;
t = 2*pi*sqrt(L0*C);
%t = 0.01;
f = @(t,u) [u(2)/(L0*((1^2/(u(1)^2+1^2))));-u(1)/C];
n = 1000
h = t/n;
listX = 0
listY = u'
for x = 0:h:t-h
k1 = f(x,u);
k2 = f((x+h)/2,u + (h/2)*k1);
k3 = f((x+h)/2,u + (h/2)*k2);
k4 = f(x+h,u + h*k3);
u = u + (h/6)*(k1+2*k2+2*k3+k4);
listX = [listX;x];
listY = [listY;u'];
end
current = listY(:,1);
voltage = listY(:,2);
evarde = (1/2)*C*voltage.^2 + (1/2)*L0*log(1+current.^2);
figure
plot(listX,current)
title("current")
figure
plot(listX,voltage)
title("voltage")
figure
plot(listX,evarde)
title("E(t)")
end
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements 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!