hi professoinals.....how to run this code

조회 수: 4 (최근 30일)
rjnt Kaur
rjnt Kaur 2013년 4월 13일
%Calculate the value of e and kp2
p=3
kpi=4
dp = 5
kp2=rand(10);
e=rand(10);
for i=1:1
j=1:5
r=e(j)*dp-kp1*kp2(i)*(p-1)
if r==1
q1=kp2(i)
q2=e(j)
break;
end
end
it doesnot show value of q1 and q2

채택된 답변

Image Analyst
Image Analyst 2013년 4월 13일
That's because r is never 1. Assuming your kpi is really kp1, then your code outputs this:
p =
3
kp1 =
4
dp =
5
j =
1 2 3 4 5
r =
-2.2984647062648 -1.68125690365354 -2.35894629559188 -6.49583211445794 -3.95680751584107
As you can see, r is never 1 so this line
if r==1
is never true and you never get to the code that would display q1 and q2.

추가 답변 (2개)

Florian
Florian 2013년 4월 13일
Hi Neet,
I have absolutely no clue what your code is supposed to do, but there are a couple of syntax proplems with what you have copied. Here is a correction with indents and ";" to show the end of a line:
%if true
%Calculate the value of e and kp2
p = 3;
kp1 = 4;
dp = 5;
kp2 = rand(10);
e = rand(10);
for i = 1:1 % This loop is redundant
for j = 1:5
r = e(j) * dp - kp1 * kp2(i) * (p-1);
if r == 1
q1 = kp2(i);
q2 = e(j);
break;
end
end
end
%end
This code runs, BUT: 1) The loop for i is redundant 2) r will likely never be equal to 1 since kp2 and e are defined as random numbers Hence, you won't get any values for q1 and q1. You should probably check what this code is supposed to do.
Cheers, Florian

rjnt Kaur
rjnt Kaur 2013년 4월 14일
Thanks Florian for your valueable time ...i want to satistisfy the equation e*dp-kp1*kp2*(p-1)=1....my code is not generating r=1..if r is equal to one then the value of e and kp2 is taken..can you suggest other method regarding this...thanking you

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by