Resolution exercise Octave

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Resolution exercise Octave

Simone
Can you help me to solve this question:

Create ranges of values ​​from one to ten and store in a variable called R1.
In R2, store non-integer values ​​in the range of one to ten, with steps of
0.2

Thank you!



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Resolution exercise Octave

nrjank
On Wed, May 6, 2020 at 8:43 PM Simone <[hidden email]> wrote:
Can you help me to solve this question:

Create ranges of values from one to ten and store in a variable called R1.
In R2, store non-integer values in the range of one to ten, with steps of
0.2

ok, I just walked my daughter through some of this as she's learning Octave/Matlab :)

Assuming you know the basics of 'storing values in a variable', you should learn how to use the colon ( : ) operator to specify a range.

see the Octave documentation page on Ranges:

it has examples for everything you should need to work through the problem. 



Reply | Threaded
Open this post in threaded view
|

Re: Resolution exercise Octave

BGreen

On Wed, May 6, 2020 at 9:01 PM Nicholas Jankowski <[hidden email]> wrote:
On Wed, May 6, 2020 at 8:43 PM Simone <[hidden email]> wrote:
Can you help me to solve this question:

Create ranges of values from one to ten and store in a variable called R1.
In R2, store non-integer values in the range of one to ten, with steps of
0.2

ok, I just walked my daughter through some of this as she's learning Octave/Matlab :)

Assuming you know the basics of 'storing values in a variable', you should learn how to use the colon ( : ) operator to specify a range.

see the Octave documentation page on Ranges:

it has examples for everything you should need to work through the problem. 




You can check whether a value (say, x) is an integer with

if floor(x)==x
% Put your code here for what will happen with integer values
end

You can check all elements of R2 with a for loop:

for j=1:length
% Type your code here for what you want to do with element number j of the array R2
end

and lastly you can remove an element form an array by setting it to be empty:

% This code removes the kth element of R2
R2(k) = [];

With these three you have all the ingredients you need - can you solve it now?


Reply | Threaded
Open this post in threaded view
|

Re: Resolution exercise Octave

Carlo de Falco-2
In reply to this post by Simone
Are you following an Octave/Matlab tutorial?

These are pretty basic constructs typical of the Octave/Matlab language,
they are described in the manual here :

  https://octave.org/doc/v5.2.0/Ranges.html#Ranges

you should really read in more details the initial part of the manual
if you are not familiar with such basic syntax.

> Il giorno 7 mag 2020, alle ore 02:14, Simone <[hidden email]> ha scritto:
>
> Create ranges of values ​​from one to ten and store in a variable called R1.

 R1 = [1 : 10]

> In R2, store non-integer values ​​in the range of one to ten, with steps of
> 0.2

 R2 = [1 : 0.2 : 10]

You can check that the values are "stored" by inspecting the workspace
with the command "whos" (or with the variable browser in the GUI)

c.