Recommended problems
Try to avoid loops!
1. problem: Plot the distribution of the bmi indecies (weigth in kg / heigth^2 in meters) according to the adatok.csv file. Find out, that
- How many people have bmi under 18?
- How many people have bmi over 25?
- How many people have bmi between 18 and 25?
ad=dlmread('adatok.csv');
bmi=ad(:,2)./ad(:,1).^2*1e4;
lessthan18=sum(bmi<18)
morethan25=sum(bmi>25)
between1825=sum(bmi<=25 & bmi>=18)
lessthan18 = 593 morethan25 = 15057 between1825 = 4350
2. problem: Answer the qustions above for people under 30 years.
young=ad(:,3)<30; youngbmi=ad(young,2)./ad(young,1).^2*1e4; lessthan18=sum(youngbmi<18) morethan25=sum(youngbmi>25) between1825=sum(youngbmi<=25 & youngbmi>=18)
lessthan18 = 93 morethan25 = 2541 between1825 = 683
3. problem: Try plotting the A=[3 4 2 3; 1 3 5 1; -9 5 2 5] matrix. Explain, what you see on the plot.
Each column is plotted with one line.
4. problem: Plot the parametrized curve x(t)=t*cost(t), y(t)=t*sin(t) while t is between 0 and 10. Label the axis, give our plot a title and save it as a jpg file.
function spiral t=linspace(0,10,100); plot(t.*sin(t),t.*cos(t)) xlabel('x axis') ylabel('y axis') title('Spiral') saveas(gca,'snail.jpg')
5. problem: Write a function called funSign, which takes thwo number as input: a and b. The function should plot the sine function on the [a,b] interval, and it's output should be 1 if the sign of the sine function is different in the point a and b, 0 is any of a or b is a root, -1 otherwise.
function out1=funSign(a,b) t=linspace(a,b); plot(t,sin(t)) if sin(a)*sin(b)<0 out1=1; elseif sin(a)*sin(b)==0 out1=0; else out1=-1; end
6. problem: Plot a half sphere.
function halfSphere
x=linspace(-1,1);
y=x;
[xx,yy]=meshgrid(x,y);
z1=1-xx.^2-yy.^2;
z1(z1<0)=0;
z1=-sqrt(z1);
mesh(x,y,z1)