Register to reply

MATLAB Exercise trouble. Puzzled on how to start off the function and it's conditions

Share this thread:
M1ZeN
#1
Jan30-12, 05:59 PM
P: 17
1. The problem statement, all variables and given/known data
Write a Matlab function that takes as input three integers n, a and b, and outputs the number
of positive integers less than n that are divisible by a or b. For example, with n = 1000, a = 3
and b = 5, the output should be 466.


2. Relevant equations
MATLAB's use of entering in the program into editor. I do not know of any functions in which to use.

3. The attempt at a solution
I have read over my classes notes over and over again (popping adderalls). I have spent a total of three full days non stop reading and trying to understand (and yes I have had sleep). I have gone through many online tutorials for MATLAB and understanding it's features and commands. However this particular homework exercise has left me completely lost.

First. I'm writing the function into the MATLAB editor. The only work I have done so far is my attempt in defining the variables (n, a & b) for the integers and my attempt at entering in the user input command where you would put in values from the Command Window.

I do know somewhere in the program I'm going to have use the operator of less than. I'm confused on the divisible part and also how to define a command to display the output of the integer that is less than n that are divisible by a or b.
Phys.Org News Partner Science news on Phys.org
Experts defend operational earthquake forecasting, counter critiques
EU urged to convert TV frequencies to mobile broadband
Sierra Nevada freshwater runoff could drop 26 percent by 2100
MisterX
#2
Jan30-12, 07:34 PM
P: 581
There are two ways to solve this, a clever way and a "brute force" way.

Some useful functions:

floor(A) : rounds down to the nearest integer.

mod(X, Y) : modulus after division - this is the same as the remainder when both X and Y are positive
If X is evenly divisible by Y, then mod(X, Y) will return 0.


Register to reply

Related Discussions
Long exercise about PDE and Green's function Calculus & Beyond Homework 2
Matlab: If/Elseif 2 conditions. Math & Science Software 2
Simple exponential function exercise Precalculus Mathematics Homework 9
Trouble with boundary conditions in Newton-Raphson method for Coupled PDEs Differential Equations 0