While loop homework problem

For any number between -1 and 1, your program calculates and outputs the arccosine and arcsine of the number in both degrees and radians. (Example: if you enter 0, arccosine is either 90 degrees or π/2 radians, and 270 degrees or 3π/2 radians.) For your convenience, your answers can be between 0 and 180 degrees (π).
This is what I've been doing. I know its wrong...The thing is it has to be like beginner MATLAB level language. i=-1;
while i<=1
i=asin(i)
i=asind(i)
i=acos(i)
end n=-1

댓글 수: 1

William
William 2011년 10월 11일
Bye the way it is bad to use "i" as variables in Matlab because it thinks "i" or "j" as the square root of -1 (Imaginary number)

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

 채택된 답변

Harry MacDowel
Harry MacDowel 2011년 10월 11일

0 개 추천

I felt a bit bored so I do the coding for you. Also I might have use for this in near future. Just run arcCosSin in command window.
Next time try a bit harder to do the homework yourself. You could get a lot of Matlab programming tips through Google.
function [] = arcCosSin()
% Written by GLO on 11.Oct.2011
inputnum = input('Please Enter a number between -1 and 1 for the arcCos and arcSin: ');
if (inputnum<-1 || inputnum>1)
fprintf('\nThis program only gives the answer for input between -1 and 1\n');
else
sinDeg = asind(inputnum);
sinRad = asin(inputnum);
cosDeg = acosd(inputnum);
cosRad = acos(inputnum);
fprintf('ArcSin in Degree is: %0.2f\n',sinDeg);
fprintf('ArcSin in Radian is: %0.5f\n',sinRad);
fprintf('ArcCos in Degree is: %0.2f\n',cosDeg);
fprintf('ArcCos in Radian is: %0.5f\n',cosRad);
end

댓글 수: 7

Jan
Jan 2011년 10월 11일
For unknown reasons the OP wants a WHILE loop.
Harry MacDowel
Harry MacDowel 2011년 10월 11일
Yeah Jan. But then when I looked at the statement of the homework again, it didn't say anything about while loop so I am thinking, maybe it's just Tamimi who thinks that he needs while loop to solve this question.
But then it's not hard to alter either. ;-)
Abdullah Tamimi
Abdullah Tamimi 2011년 10월 11일
i could actually use if/else/elseif also. sorry my teacher wrote the book for the class and he didnt tell us how to do this
Harry MacDowel
Harry MacDowel 2011년 10월 11일
so does the code fit your objectives?
Abdullah Tamimi
Abdullah Tamimi 2011년 10월 11일
It does, but too well...
I tried rewriting it so it fits what my teacher is looking for, but im pretty sure im doing something wrong
if (x<-1 || x>1)
else
x=asind(x)
x=asin(x)
x=acosd(x)
x=acos(x)
end
Harry MacDowel
Harry MacDowel 2011년 10월 11일
if (x<-1 || x>1)
(you have to tell the program what to do here)
else
Abdullah Tamimi
Abdullah Tamimi 2011년 10월 11일
wait i have to tell it to do all those cos and sin functions. what do i put heeeeeeelppppppp

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

추가 답변 (1개)

William
William 2011년 10월 11일

1 개 추천

for ii = -1:0.001:1
asind(ii)
asin(ii)
acosd(ii)
acos(ii)
end

댓글 수: 1

Abdullah Tamimi
Abdullah Tamimi 2011년 10월 11일
but it sort of doesnt correctly answer the question, it asks for you to enter a number to get an answer, not to get a list of all answers

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by