Filter löschen
Filter löschen

How can put the values inside tolerances?

1 Ansicht (letzte 30 Tage)
theintern
theintern am 19 Okt. 2017
Kommentiert: KL am 20 Okt. 2017
for i=1:length(As1)
[vq]=dd(Vs1,As1(i));
As = vq.*(Us(j).^2)./(16.*(pi.^2).*msksi.*fs1(j));
res1=As1(i)-As;
if abs(res1)<0.01
As1(i)=As;
Us(j)=Vs.*fs(j);
break
end
  11 Kommentare
KL
KL am 20 Okt. 2017
Bearbeitet: KL am 20 Okt. 2017
I have removed the equations and replaced them with dummy functions.
@theintern: No hard feelings, this is an open forum and we are all volunteers here just because we like what we do and to share the knowledge and learn together.
These things can happen, not to mention you'd have been stressed to finish your task before the deadline. You have posted your question with fairly decent descriptions (compared to homework questions which we see on daily basis) with whatever you've tried. But next time, if the code is not allowed to be posted online, try to emulate it as a minimal problem so we can understand your original situation and help you. Good luck!
Rik
Rik am 20 Okt. 2017
I agree with Jan and KL. Sweating it is never nice, so you should learn from it, which I think you did.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

KL
KL am 19 Okt. 2017
Bearbeitet: KL am 20 Okt. 2017
Firstly, you don't need those digdata, digdata2 functions. You're code is very slow because of them. You're loding the same mat files again and again for more than 40000 times. secondly, you should move those lines outside the inner loop, why do the same thing 201 times everytime?!.
So here's the cleaned up code, this is faster so it's much easier now to figure out what's your problem.
ms=1;
msksi=0.013;
Vs1=5.5;
As1=0.05:0.005:1.05;
fs1=0.5:0.005:1.5;
%load the data only once!!
m = load('myarray.mat');
myarray = m.myarray;
d = load('datas2.mat');
datas2 = d.datas2;
loop=0;
for i=1:length(As1)
%do it here, why repeat the very same thing 200 times everytime!
vq(i) = griddata(myarray(:,1),myarray(:,2),myarray(:,3),Vs1,As1(i));
vq2(i) = griddata(datas2(:,1),datas2(:,2),datas2(:,3),Vs1,As1(i));
for j=1:length(fs1)
Us(j)=Vs1.*fs1(j);
As(i,j) = func_find_As(vq(i),Us(j),mksi,fs1(j));
fs(i,j) = func_find_fs(vq2(i),Us(j),ms,As1(j));
[res1(i,j), res2(i,j)] = calculateRes(As(i,j),As1,fs(i,j),fs1);
[As1, fs1, Us] = checkTolerance(res1,res2);
end
loop=loop+1;
end
  6 Kommentare
theintern
theintern am 20 Okt. 2017
I am really appreciated @KL ! Thank you so much, I learned many things thanks to you.
KL
KL am 20 Okt. 2017
You're very welcome!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Rik
Rik am 19 Okt. 2017
What do you mean, it doesn't stop? These are for-loops, so they will exit. Do you mean you want to break out of both loops at the same time? If that is the case, the code structure below should help.
BreakLoop=false;
for i=1:length(As1)
if BreakLoop,break,end
for j=1:length(fs1)
...
if abs(res1)<0.01 && abs(res2)<0.01
BreakLoop=true;
break
end
end
end
  1 Kommentar
theintern
theintern am 19 Okt. 2017
I mean the fs1 value never go into tolerance.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by