# Matlab odd

## Odd and even numbers

Aneven numberis a number which has a remainder of0 upon division by2, while anodd numberis a number which has a remainder of1 upon division by2.

If the units digit (or ones digit) is 1,3, 5, 7, or 9, then the number is called anodd number, and if the units digit is 0, 2, 4, 6, or 8, then the number is called aneven number (for the set of numbers 0-9). Thus, the set of integers can be partitioned into two sets based on parity:

• the set ofeven(or parity 0) integers
• the set ofodd(or parity 1) integers.

**Parity is a fundamental property of integers, and many seemingly difficult problems can be solved by making parity arguments.

The below function is to find the details of even and odd number in a given list

function [sum_even,sum_odd,n_even,n_odd] = even_odd(x)

sum_even = 0;

sum_odd = 0;

n_even = 0;

n_odd = 0;

for i=1:1:x

if mod(i,2)==0

sum_even=sum_even+i;

n_even=n_even+1;

else

sum_odd=sum_odd+i;

n_odd=n_odd+1;

end

end

Example set for list:1,2,3,4,5,6,7,8,9,10

sum_even = 30, which is 2+4+6+8+10 = 30

sum_odd = 25 , which is 1+3+5+7+9 = 25

n_even = 5, which are 2,4,6,8,10

n_odd = 5, which are 1,3,5,7,9

I hope this helps.

## Matlab sum of odd numbers bhlzn9aoi7g1zhez304o8iobbj32oimsvfblbmaryplr31ayfyxaj381xaga

Sours: http://tsatsakisae.gr/ec6omh/avly.php?diko=matlab-sum-of-odd-numbers

## Using an if statement to differentiate between odd and even numbers

Given two Qbar matricies and the number of ply layers in a composite, I am trying to calculate the A,B, and D stress matricies.

My first error is calculating h. Given an even number of ply, h is calculated one way, and given an odd number of ply, h is calculated another way. I have tried coding that below but all my attempts have been unsuccessful.

My second problem is figuring out how to tell matlab that the odd numbered layers draw their values from one Qbar matrix and the even numbered layers draw their values from a different Qbar matrix and all the values are summed.

function[A B D] = ABD(Qbar1,Qbar2,n)

x = 0:1:n;

if n == 2*x+1 % odd number of ply

h = -(n/2):1:(n/2);

elseif n == 2*x

h = -n:1:n;

end

disp(h)

for k = 1:n; i = 1:3; j = 1:3;

for k = [1 3 5]

Qbar(i,j,k) = Qbar1;

end

for k = [2 4]

Qbar(i,j,k) = Qbar2;

end

A(i,j) = Qbar(i,j,k)*(h(k+1)-h(k));

B(i,j) = (1/2)*Qbar(i,j,k)*((h(k+1)^2)-(h(k)^2));

D(i,j) = (1/3)*Qbar(i,j,k)*((h(k+1)^3)-(h(k)^3));

end

.

## Odd matlab

.

.

### Similar news:

.

275 276 277 278 279