How can put the values inside tolerances?

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 commentaires

KL
KL le 19 Oct 2017
Modifié(e) : KL le 19 Oct 2017
what's myarray? I didn't ask you last time.
theintern
theintern le 19 Oct 2017
myarray is data that I attached .
KL
KL le 19 Oct 2017
and what is digdata2? If you have problems with fs1, you should trace it back there, I suppose.
theintern
theintern le 19 Oct 2017
Thank you, I attached all of codes. digdata2 is same with digdata except datas. I use myarray in digdata and datas2 in digdata2.
Rik
Rik le 19 Oct 2017

This is not a free private consultancy forum. It is frowned upon to remove a question once you have a solution. It is really rude to do so. If you want to keep solutions to your problems private, hire a private consultant.

theintern
theintern le 19 Oct 2017
Modifié(e) : theintern le 19 Oct 2017
Sorry, you misunderstood.. The place where I work said it should be private, and then I had to delete it. But in the comments there are still everything. This is not what you think. Thanks to everyone who helped me.
Jan
Jan le 19 Oct 2017
@theintern: Your excuse is welcome. Thanks for this. You have learned now, that deleting question is disliked massively here for good reasons. But it can happen, that you have published something without knowing, that it is a private property. Nevertheless, this is the world wide web, not a playground. You can still find the removed details in e.g. Google'c cache. It is not a secret that internet users have to think at least twice, before they publish anything.
Remember, that you agreed to the terms of use. Read it again, the part "Contents" is important here. The admins and editors can restore your question, and if you do not provide a good reasons and excuse, they will.
Please replace "deleted" by a short statement, which calms down Rik and convinces e.g. me not to restore the original question. But the admins and other editors will decide by their own.
theintern
theintern le 19 Oct 2017
I apologize to everyone, I am in a difficult situation. I wasn't know it and the thing that I want to do was not that. Thanks for understanding.
Jan
Jan le 20 Oct 2017
My opinion: Okay. @Rik: Perhaps you want to remove the flag now?
KL
KL le 20 Oct 2017
Modifié(e) : KL le 20 Oct 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 le 20 Oct 2017
I agree with Jan and KL. Sweating it is never nice, so you should learn from it, which I think you did.

Connectez-vous pour commenter.

 Réponse acceptée

KL
KL le 19 Oct 2017
Modifié(e) : KL le 20 Oct 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 commentaires

theintern
theintern le 19 Oct 2017
Ok, thank you so much to make it easy. I will work on it.
theintern
theintern le 19 Oct 2017
But still, I can't see the problem.
KL
KL le 19 Oct 2017
Check my updated code. Here you see the crucial variables as 201x201 matrix. You can proceed from here on. As you can see, at no point you get res1 and res2 below 0.01, which makes me think either you've got some equations wrong or something to do with your parameters.
theintern
theintern le 19 Oct 2017
Ok thank you so much! I will check the equations and datas. Thanks for all of this.
theintern
theintern le 20 Oct 2017
I am really appreciated @KL ! Thank you so much, I learned many things thanks to you.
KL
KL le 20 Oct 2017
You're very welcome!

Connectez-vous pour commenter.

Plus de réponses (1)

Rik
Rik le 19 Oct 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

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Question posée :

le 19 Oct 2017

Commenté :

KL
le 20 Oct 2017

Community Treasure Hunt

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

Start Hunting!

Translated by