Symsum function for basic electrical engineering calculations.

조회 수: 5 (최근 30일)
I am trying to write a symsum function so that i can calculate different basic Electrical engineering functions with Integrals (Average,effective value and equivalency)
I have this piece of code wich is built for a cos/sin funktion and im trying to change it so that i can also build a sum function (symsum) to make it do the same calculations. As a example I am trying to simulate this signal:
with
für = for ,and, sonst = otherwise
with T = 10ms, u0 = -2 and u1 = 10,
I wrote this Code based on another code and I want to build this to fit the u(t) function. It might be that the Uav, Uaav and Ueff wont work with the u(t) i want to build, but that is another problem. My main problem is that I cant make the variabel u working so that I can get the signal. I wouldnt really need the -inf to the inf only a period(like 0 - 10ms per period) (for the later functions Uav,Uaav,Ueff) but that doenst really change my problem as the symsum function doesnt seem to work.
clear all;
close all;
u0 = -2; % Volt
u1 = 10; % Volt
T = 0.001; %10ms
tmin = 0;
tmax = T;
N = 100;
t = linspace(tmin,tmax);
t1 = transpose(t);
It didnt accept t and so i used t1 to transpose it.
s = [tmin,tmax];
n = log(0);
k = log(0);
F = sum(s.*(t1-(n.*T)),k,n,Inf);
u = (u0+u1)*F;
The " s.*(t1-(n.*T)) " really seems to be the troubling part and I tried different things but I cant solve it. I also think that the variable F is a bit Fishy.
Uav = trapz(t,u)/T;
Uaav = trapz(t,abs(u))/T;
Ueff = sqrt(trapz(t,u.^2)/T);
disp(["Mittelwert: ",num2str(Uav)," Volt"]);
disp(["Gleichrichtwert: ",num2str(Uaav)," Volt"]);
disp(["Effektivwert: ",num2str(Ueff)," Volt"]);
plot(t*1000,u,"r");
grid on;
xlabel("t/ms");
ylabel("u(t)/V");
A friend of mine also suggested to build a "for" loop but I think the symsum function would give me what I need.
I solved the problem on paper already but I cant get it to transfer it onto a matlab code.
  댓글 수: 2
Paul
Paul 2021년 3월 5일
I'm not quite sure what the question really is. I ran the code and the F= line resulted in an error. The original question refers to symsum(), which is Symbolic Math Toolbox Function. Are you looking for symbolic answers for Uav, Uaav, and Ueff? Or numerical answers?
Samuel the Helpless
Samuel the Helpless 2021년 3월 6일
I am tring to find out why my Symsum function does not work. Thats my primary goal. Matlab gives me an error wich I dont know how to solve. The other functions Uav,Uaav and Ueff are irrelevant for my problem.
F = symsum(s.*(t1-(n.*T)),k,n,Inf);
ok that is a mistake. it should be symsum.
It should take the seconds value from "min time - steps * max Time" to build the periods of the signal. If i understand it correctly. Just thought maybe somebody more experienced with symsum found some small mistake that I dindt know about.
I am looking for numerical answers when looking at Uav, Uaav, Ueff but that is not relevant to the Symsum function not working

댓글을 달려면 로그인하십시오.

채택된 답변

Paul
Paul 2021년 3월 6일
symsum() is a function in the Symbolic Math Toolbox and takes in symbolic inputs. If I understand that code correctly, all of the variables are doubles, which causes an error in symsum()
T = 0.001; %10ms
tmin = 0;
tmax = T;
N = 100;
t = linspace(tmin,tmax);
t1 = transpose(t);
s = [tmin,tmax];
n = log(0);
k = log(0);
F = symsum(s.*(t1-(n.*T)),k,n,Inf);
Undefined function 'symsum' for input arguments of type 'double'.
A symbolic expression for F can be formed as:
clear
syms t T n real
s(t,T) = t/T*(heaviside(t)-heaviside(t-T));
F(t,T) = symsum(s(t-n*T,T),n,-inf,inf) % sum from -inf to inf as in the original question
F(t, T) =
-(symsum((heaviside(t - T + T*n) - heaviside(t + T*n))*(t + T*n), n, 1, Inf) + symsum((heaviside(t - T - T*n) - heaviside(t - T*n))*(t - T*n), n, 0, Inf))/T
But there doesn't seem to be much that can be done with this result. Difficult to fplot() it, difficult to evaluate it. Changing the bounds in symsum to finite values makes the result much easier to work with.
If the goal is to just get a numerical expression for F:
clear
F = @(t,T) (mod(t,T)./T); % evaluate F at desired values of t and T
% for example
t=-3:.001:3;
plot(t,F(t,0.75));

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by