필터 지우기
필터 지우기

How to have use int() in a for loop?

조회 수: 6 (최근 30일)
Seba.V
Seba.V 2020년 4월 22일
답변: Walter Roberson 2020년 4월 22일
Hi there
The goal of this loop is to plot the value of A over a defined set of angles values al.
I believe the integrating function is giving the following error:
Error using symengine
Invalid argument.
Error in sym/int (line 162)
rSym = mupadmex('symobj::intdef',f.s,x.s,a.s,b.s,options);
Is there a way to integrate a and gradually plot the values from an array?
I hope this makes sense
syms x
B=(pi-asin(1/2))
al=asin(1/2):0.001:B;
V=200*sin(x);
i=1;
for i=al(i)
F=double(subs(100*2*pi+int(V,x,al,B)-100*(B-al)))
Vdc=F/(2*pi);
A=(Vdc-100)/2
plot(al,A)
i=i+1
end

채택된 답변

Walter Roberson
Walter Roberson 2020년 4월 22일
syms x
B=(pi-asin(1/2));
al=asin(1/2):0.001:B;
V=200*sin(x);
nal = numel(al);
A = zeros(size(al));
for i = 1 : nal
F=double(subs(100*2*pi+int(V,x,al(i),B)-100*(B-al(i))));
Vdc=F/(2*pi);
A(i)=(Vdc-100)/2;
end
plot(al, A)
This is rather slow (!!) The secret to doing int() in a for loop faster, is not to do int() inside a for loop. Instead, do the int() once before the loop, using a symbolic lower bound, and then subs() the numeric lower bound into that; you can do all the calculations in vectorized form.

추가 답변 (1개)

KSSV
KSSV 2020년 4월 22일
syms x
B=(pi-asin(1/2))
al=asin(1/2):0.001:B;
V=200*sin(x);
i=1;
for i=1:length(al)
I = double(int(V,x,al(i),B)) ;
F=((100*2*pi+I-100*(B-al(i))))
Vdc(i) = F/(2*pi);
A(i) =(Vdc-100)/2 ;
end

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by