logspace equivalent and sin(x) [solved]

조회 수: 5 (최근 30일)
Giacomo Lorenzi
Giacomo Lorenzi 2019년 11월 10일
댓글: Steven Lord 2019년 11월 11일
Hello, I have to solve a couple of exercises; the first one asks me to write with ":" the equivalents of this:
x=linspace(0, 10, 5);
x=linspace(-5, 5);
x=logspace(1, 3, 3);
x=logspace(1, 3, 5);
I solved the first by myself ( x=[0:2.5:10] ) because it's easy, but I really can't understand the others; actually I don't just want to solve the exercises but I want to understand if there is actually a method and how it is done.
Second one is this: A = {sin(x), x=1,2, ,1000}, I have to find how many elements of A are bigger than 1/2 using function SUM; actually I don't know that writing, I just started using Matlab, but even Matlab gives me an error, so maybe I thought it was wrong written; any guesses?

채택된 답변

Stephan
Stephan 2019년 11월 10일
x = 10.^(1:3) % x=logspace(1, 3, 3)
result = sum(A>0.5) % Number of elements in A bigger than 0.5
  댓글 수: 2
Stephan
Stephan 2019년 11월 10일
편집: Stephan 2019년 11월 10일
x = 10.^(1:0.5:3) % x=logspace(1, 3, 5)
Giacomo Lorenzi
Giacomo Lorenzi 2019년 11월 10일
Thanks a lot!

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

추가 답변 (2개)

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019년 11월 10일
a=1;
b=3;
c=3;
logspace(a, b, c)==10.^(1:(b-a)/(c-1):b) %are equivalent
on the other hand
x=1:1000;
A=sin(x);
total=sum(A>1/2)

Giacomo Lorenzi
Giacomo Lorenzi 2019년 11월 10일
Thanks guys, you were really helpful. However I still don't know how to solve the last
x = logspace(1, 3, 5)
it seems very tricky to me; the formula used for the previous one was pretty "standard", this is more "strange". Don't you know how to solve this too?
  댓글 수: 1
Steven Lord
Steven Lord 2019년 11월 11일
You could "cheat" a little and look at what logspace does.
type logspace.m
I'm using type rather than edit to avoid accidentally modifying logspace. It's short enough that this won't display too much in the Command Window.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by