help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: having difficulty using a for loop to solve an equation


From: Kire Pudsje
Subject: Re: having difficulty using a for loop to solve an equation
Date: Tue, 20 Jun 2017 06:21:09 +0200



On Tue, Jun 20, 2017 at 1:47 AM, naryana.shankara <address@hidden> wrote:
here is my task:
<http://octave.1599824.n4.nabble.com/file/n4683785/Screenshot_2017-06-19_17-54-18.png>

Create two arrays x and y, whose entries are defined as
x  = i,
y  = j
i = 1, 2, 3, 4, 5.
y=5 − 2j,
j = −2, −1, 0, 1, 2.
Then, compute the cubed sum of these two vectors in two different ways.
First, use a for loop
to construct the vector z as
z  = (x + y )^ 3 ,
i = 1, 2, 3, 4, 5.
my code:
%Vectorization
clc;
clear;
%x=i;                %array created per spec
%i=[1 2 3 4 5];      %array created per spec
y=5-2j;             %array created per spec
j=[-2 -1 0 1 2];    %array created per spec

First of all, I would say it is an ill-formed question.
In the introduction, two arrays are defined, however the position is also defined, especially for the y-array.
So in a formal sense only z1 and z2 are defined.

When declaring your array, first define the index then use it.
j=-2:2;
y=5-2*j;
Likewise for x.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]