how do i write an algorithm

조회 수: 5 (최근 30일)
Antwone Goodwyn
Antwone Goodwyn 2019년 5월 3일
편집: Antwone Goodwyn 2019년 5월 6일
Develop M-file that can do followings
- Ask you to input the functions f1(x)=x.^2; f2(x)=x.^3; where x is -100, -99, -98........, 99, 100
- Find and plot fsum(x)=f1(x)+f2(x)
What i could come up with
ni=0
nf=100
for x=ni+nf;
f1(ni)=ni^2;
f2(nf)=nf^3;
fsum(x)=f1(ni)+f2(nf);
end
plot(fsum);
  댓글 수: 3
Rik
Rik 2019년 5월 3일
You can find guidelines for posting homework on this forum here.
Antwone Goodwyn
Antwone Goodwyn 2019년 5월 6일
okay thank you

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

채택된 답변

Raj
Raj 2019년 5월 6일
ub=input('Enter upper bound:')
lb=input('Enter lower bound:')
f1=zeros(ub-lb+1,1);
f2=f1;
fsum=f2;
for i=lb:ub
f1(i+101,1)=i^2;
f2(i+101,1)=i^3;
fsum(i+101,1)=f1(i+101,1)+f2(i+101,1);
end
fsum
plot(fsum)
Always post your attempt (even if wrong) while posting homework questions.
  댓글 수: 1
madhan ravi
madhan ravi 2019년 5월 6일
Posting a complete solution is not recommended.

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

추가 답변 (1개)

Antwone Goodwyn
Antwone Goodwyn 2019년 5월 6일
i apologize. i am new to the MatLab community. However, thank you a lot.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by