You are on page 1of 26

Soru 1

Code is given below


fh = @(x) 4*sin (1.5*x)*exp((-0.3)*x) + 2*cos
(1.3*x)*exp(0.5*x);
fp = fplot (fh, [-10 10]);
fp.Color = 'r';
fp.LineWidth = 2;
fp.Marker = '.';
fp.MarkerSize = 10;
fp.MarkerEdgeColor = 'm';
grid on
title('The graph of f(x)')
xlabel('x');
ylabel('f(x)');

I have given the essential code. Simply change the characteristics according to your
requirement(the 'fp.______ = ' values). You can undoubtedly transform them to
satisfy to make the plot resemble the figure. I dont have MATLAB programming. Ran
it on Octave. The diagram was same. Expectation you comprehended the idea.
Soru 2
The code of the given program is attached below in the code block.

% Define x and fx
x = 0:0.5:15;
fx = @(x) 3 * x.^3 .* exp(-x) + x.^(3/2);

% Compute the derivative of fx using the diff function


dx = diff(x);
dfdx = diff(fx(x)) ./ dx;
% Plot fx and d(f)/dx on the same graph
hold on;
plot(x, fx(x), '-o', 'MarkerSize', 6, 'LineWidth',
1.5,"MarkerFaceColor","white","MarkerEdgeColor","blue"); % plot fx
with circle markers

plot(x(2:end), dfdx, ':o', 'MarkerSize', 6, 'LineWidth',


1.5,"MarkerFaceColor","#ff00ff"); % plot d(f)/dx with dashed line
and circle markers
hold off;
grid on
% Add title and axis labels
title('Function fx and its derivative');

ylabel('f for d(f)/dx');

% Add legend
legend('f(x)', 'd(f)/dx');

Explanation:
Soru 3
%solution1

selectedRows1 = data.gdp_growth_2009 > 0;

statesWithPositiveGrowthRateIn2009 = data.state(selectedRows1);

%solution2

selectedRows2 = data.gdp_growth_2009 > 0 & data.gdp_growth_2010 < 0;

stateWithPositiveGrowthIn2009AndNegativeIn2010 = data.state(selectedRows2);

%solution3
selectedRows3 = data.gdp_growth_2009 > 0 & data.gdp_growth_2010 > 0 &
data.gdp_growth_2011 > 0 & data.gdp_growth_2012 > 0;

stateWithPositiveGrowthInAllYear = data.state(selectedRows3);

stateWithNegativeGrowthInAllYear = data.state(~selectedRows3);

%solution4

selectedRows4 = data.gdp_growth_2009 == 0 | data.gdp_growth_2010 == 0 |


data.gdp_growth_2011 == 0 | data.gdp_growth_2012 == 0;

stateWithZeroGrowthInAnyYear = data.state(selectedRows4);

%i didnt have the actual data so, showing u demo with dummy data

testData = data(5:10, :)

testData =

6×10 table

Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10

_________________ ____ ____ ____ ____ ____ ____ ____ ____ _____

{'Connecticut' } 0.8 -1.6 4.6 -2.4 4.3 1 2.1 0.9 44

{'Maine' } 1.3 3.3 2.8 -1.8 4.8 0.6 2.1 1.9 34

{'Massachusetts'} 3.2 4 2 1.2 4.4 1.5 2.2 2.1 28

{'New Hampshire'} 5.1 1.2 2.3 -2.2 8.6 1.4 2.2 2 33

{'Rhode Island' } 0.2 2.6 -3 5.9 4.8 1.5 1.6 2.2 23

{'Vermont' } 0.5 3.3 0.3 1.1 5.7 1.3 1.8 2.3 21

testData.Var1(testData.Var3 < 0)

ans =

1×1 cell array

{'Connecticut'}

testData.Var1(testData.Var3 > 0)

ans =
5×1 cell array

{'Maine' }

{'Massachusetts'}

{'New Hampshire'}

{'Rhode Island' }

{'Vermont' }

testData.Var1(testData.Var3 < 0 & testData.Var4 > 0)

ans =

1×1 cell array

{'Connecticut'}

testData.Var1(testData.Var3 < 0)

ans =

1×1 cell array

{'Connecticut'}

testData.Var1(~(testData.Var3 < 0))

ans =

5×1 cell array

{'Maine' }

{'Massachusetts'}

{'New Hampshire'}

{'Rhode Island' }

{'Vermont' }

testData.Var1((testData.Var3 == -1.6) | (testData.Var4 == 4.6))

ans =

1×1 cell array


{'Connecticut'}

thankyou...........
Soru 4
======= matlab code for the asked problem===========

gdp_growth_2009 = randi([-10 15],1,50);%% first data set of random gdp 2009


gdp_growth_2012 = randi([-10 15],1,50);%% second data set of random gdp
2012
stem(gdp_growth_2009,'fill','Color','b');%stemming first data set
hold on;
stem(gdp_growth_2012,'fill','Color','r');%%stemmng second dataset
%% XTick label
set(gca,'XTickLabel',{'AK','AZ','CT','FL','IN','IA','IL','ME','MO','NC','NH','NV','CK','
RI','TN','VA','WI'});
legend('2009','2012');%%creating legend

title(''Growth rates of 2009 and 2012);


hold off;
Soru 5
Solution:
clc
clear all
close all
format long
x=-5:0.01:5;
y=normpdf(x);
y1=tpdf(x,1);
y2=tpdf(x,2);
y4=tpdf(x,4);
y10=tpdf(x,10);
plot(x,y,'r',x,y1,'-k',x,y2,'-y',x,y4,'-g',x,y10,'-b');
xlabel('x');
ylabel('Density');
title('Probability Density Function of N(0,1) and t_v');
legend('N(0,1)','t_1','t_2','t_4','t_{10}');
Soru 6
clear all;

load crime.txt;
% 5 columns:
% column1 = crime
% column2 = household income
% column3 = house values
% column4 = latitude coordinate
% column5 = longitude coordinate

crimes = crime(:,1); % Get crime data


household_incomes = crime(:,2); % Get household income data
house_values = crime(:,3); % Get house values data

%%%%%%% Subplot 1 of 2 %%%%%%%


subplot(1,2,1);
% Create a scatter plot between crime and house values
scatter(house_values, crimes,'MarkerEdgeColor', 'k',
'MarkerFaceColor', 'b', 'LineWidth', 1.5);
title('Crime versus House Values'); % Add a title to plot
xlabel('House Values'); % Add x-axis label to plot
ylabel('Crime'); % Add y-axis label to plot
grid on; % Display major grid lines

%%%%%%% Subplot 2 of 2 %%%%%%%


subplot(1,2,2);
% Create a scatter plot between crime and household income
scatter(household_incomes, crimes,'MarkerEdgeColor', 'k',
'MarkerFaceColor', 'r', 'LineWidth', 1.5);
title('Crime versus Household Income'); % Add a title to plot
xlabel('Household Income'); % Add x-axis label to
plot
ylabel('Crime'); % Add y-axis label to
plot
grid on; % Display major grid
lines
Soru 7
mean = 1.5;
bins = 50;
variance = 3;
std = sqrt(variance);
a = std;
b = mean;
y = a.*randn(2000,1)+b;
xlabel('X);
Ylabel('Density');
histogram(y,bins);
h= histfit(y);
legend('Histogram',Density Curve')

title('Histogram and Density Curve');

h(1).FaceColor =[0.9333 0.5098 0.9333];

h(2).Color = [0 0.4470 0.7410];

You might also like