help-octave
[Top][All Lists]
Advanced

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

Re: I am trying to enter a function and input multiple variables


From: Maynard Wright
Subject: Re: I am trying to enter a function and input multiple variables
Date: Sun, 03 Jul 2016 16:54:27 -0700
User-agent: KMail/4.13.3 (Linux/3.16.0-30-generic; KDE/4.13.3; i686; ; )

On Sunday, July 03, 2016 03:19:44 PM naryana.shankara wrote:
> I have 2 functions:
> (cot(x))-1
> (cos(2*(x)))/((1+(cot(x)))*(sin(x))^2)
> and I need to enter the same values and compare the outputs.  This is a loss
> of significance problem for a math class.
> The values are
> (pi/4),((5*pi)/4),((3*pi)/4) and ((7*pi)/4)
> 
> my code is
> clear all
> A=(cot(x))-1
> B=(cos(2*(x)))/((1+(cot(x)))*(sin(x))^2)
> x=[(pi/4),((5*pi)/4),((3*pi)/4),((7*pi)/4)]
> x*A
> x*B
> 
> my output is
> 
> >>>error: `x' undefined near line 2 column 8
> 
> error: evaluating argument list element number 1
> error: called from:
> error:   /home/shankara/Documents/M365/HW2P2.m at line 2, column 2
> 
> I know I am doing something like comparing a function with a vector and
> octave is grumbling.
> 
> What am I doing wrong and what should my code look like?
> 
> thanks
> 

I can run your code successfully with two changes:

1.  I moved the line defining x so that x is defined before I run the lines for 
A and B;

2.  In the line for B, I prefixed the various operators with "." to indicate 
that I wanted operations on individual elements of each matrix, not matrix 
operations:

B=(cos(2.*(x)))./((1.+(cot(x))).*(sin(x)).^2)

I probably didn't need all of those, for the plus sign for instance, but it is 
sometimes easier just to use the period as a prefix for every operator when you 
don't want matrix manipulations.


Maynard Wright




reply via email to

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