I have to solve this without hard codingSolutionHello As men

I have to solve this without hard coding.

Solution

Hello,

As mentioned, the resistance of material decreases as the intensity of light falling on it decreases.Hence , obviously , when the material is placed farther, light to which it is exposed decreases and so the resistance is more compared to when the material is placed nearer.

__ The Complete Matlab Script is as follows. And then each step is described in detail.

% Step1 : Plot the available data
Distance = [1,3,6,10];

A_Resistance = [79,400,1100,2500];

B_Resistance = [150,840,2500,4900];

C_Resistance =[460,2500,6900,15000];
figure;
plot(Distance, A_Resistance, \'color\',\'b\')
hold on;
plot(Distance, B_Resistance, \'color\',\'r\')
hold on
plot(Distance, C_Resistance, \'color\',\'g\')
xlabel(\'Distance in meters\');
ylabel(\'Resistance in Ohms\');
legend(\'Material A\', \'Material B\',\'Material C\');
title(\'Resistance Vs Distance from Light Source\');

%Step : 2- find the Coeeficients

A = polyfit(Distance,A_Resistance,3)

B = polyfit(Distance,B_Resistance,3)

C = polyfit(Distance,C_Resistance,3)

%Step 3 - Trendline Plot from Trendline Equations
% Lets plot for distance ranging from 1 to 20 and add the above equations
% appropriately

Distance_new = 1:20
A_Resistance_new = polyval( A, Distance_new)
B_Resistance_new = polyval( B, Distance_new)
C_Resistance_new = polyval( C, Distance_new)
figure;
hold on;
plot(Distance_new,A_Resistance_new,\'ro-\',\'LineWidth\',2,\'color\',\'b\')
hold on
plot(Distance_new,B_Resistance_new,\'ro-\',\'LineWidth\',2,\'color\',\'r\')
hold on;
plot(Distance_new,C_Resistance_new,\'ro-\',\'LineWidth\',2,\'color\',\'g\')
xlabel(\'Distance_New in meters\');
ylabel(\'Resistance_New in Ohms\');
legend(\'A :0.233*X^3 + 12.234*X^2 +108.533*X -41.99\',...
\' B :-3.89*X^3 + 80.5*X^2 +73.33*X + 2.13*10^-13\',...
\' C : 1.06*X^3 + 99.96*X^2 +633.95*X -272.85\' );
title(\'Trendline of Resitances with respect to Distances\');

--- Script is explained step wise below

Step1 : Create a proper plot of data

Distance = [1,3,6,10];

A_Resistance = [79,400,1100,2500];

B_Resistance = [150,840,2500.4900];

C_Resistance =[460,2500,6900,15000];

plot(Distance, A_Resistance, \'color\',\'b\')
hold on;
plot(Distance, B_Resistance, \'color\',\'r\')
hold on
plot(Distance, C_Resistance, \'color\',\'g\')
xlabel(\'Distance in meters\');
ylabel(\'Resistance in Ohms\');
legend(\'Material A\', \'Material B\',\'Material C\');
title(\'Resistance Vs Distance from Light Source\');

Result :

Prob :Now, the resistances of 3 different types of material increases as the distance from light source increases. But there is no linear or quadratic behaviour of resistances with distances. i,e we cannnot easily predict the resistances of A,B,C at someother distance ( like 11 m /12m ).

Solution :So, we have to find an equation which helps in finding the resistance for any distance. We need to find the value of Y ( here - resistance ) for some X( here-distance). The equation can be in the form of Y = a*X^3 + (b*X^2) + (c*X) +d , of which X is known , Y is to be found out , a,b,c,d are constants.

Now, to find the values of a,b,c,d we use POLYFIT function of MATLAb

Matlab Script would be :

Execute the bold script in Matlab

%Finding the relation between distance of light Source and Resistance of Material %

% From the available data, we have distance and resistances as follows

Distance = [1,3,6,10];

A_Resistance = [79,400,1100,2500];

B_Resistance = [150,840,2500.4900];

C_Resistance =[460,2500,6900,15000];

A = polyfit(Distance, A_Resistance,3); %Here 3 indicates order of the polynominal

B = polyfit(Distance, B_Resistance,3);

C = polyfit(Distance, C_Resistance,3);

The Result would be :

  

A =

Column 1

0.233333333333333

Column 2

12.2333333333334

Column 3

108.533333333333

Column 4

-41.9999999999995

B =

Column 1

-3.88888888888889

Column 2

80.5555555555556

Column 3

73.3333333333333

Column 4

2.13944434834043e-13


C =

Column 1

-1.06349206349208

Column 2

99.9682539682542

Column 3

633.95238095238

Column 4

-272.85714285714

-- where column 1 , column2 , column3, column4 indicates the unknown coefficients.

Hence, for Material A :

The Relation between Resistance and Distance is

A_Resistance = 0.233*X^3 + 12.234*X^2 +108.533*X -41.99

If you need to find the resistance at distance 15 m , put X = 15 in above equation.

So, Power Model for Material A :

  A_Resistance = 0.233*X^3 + 12.234*X^2 +108.533*X -41.99 , where X is the distance ----(1)

Power Model for Material B :

B_Resistance = -3.89*X^3 + 80.5*X^2 +73.33*X + 2.13*10^-13----(2)

Power Model for Material C :

C_Resistance =  1.06*X^3 + 99.96*X^2 +633.95*X -272.85---(3)

Above Equations (1),(2),(3) describe the trend followed by the materials. Hence these can be called as Trendline Equations.
Step 3 : To add the Trendline and Trendline Equations to the Graph

% Lets plot for distance ranging from 1 to 20

% Command polyval : It substitues values of coefficients (a,b,c ) and distance ( X) in the equations (1), (2),(3) and finds the values of Y in a simpler way. It is an inbuilt matlab function and it requires only the values of Coefficients and X as input. Using this command we can find resistances for any distance in a single line.

Distance_new = 1:20
A_Resistance_new = polyval( A, Distance_new)
B_Resistance_new = polyval( B, Distance_new)
C_Resistance_new = polyval( C, Distance_new)
hold on;
plot(Distance_new,A_Resistance_new,\'ro-\',\'LineWidth\',2,\'color\',\'b\')
hold on
plot(Distance_new,B_Resistance_new,\'ro-\',\'LineWidth\',2,\'color\',\'r\')
hold on;
plot(Distance_new,C_Resistance_new,\'ro-\',\'LineWidth\',2,\'color\',\'g\')

I have to solve this without hard coding.SolutionHello, As mentioned, the resistance of material decreases as the intensity of light falling on it decreases.Hen
I have to solve this without hard coding.SolutionHello, As mentioned, the resistance of material decreases as the intensity of light falling on it decreases.Hen
I have to solve this without hard coding.SolutionHello, As mentioned, the resistance of material decreases as the intensity of light falling on it decreases.Hen
I have to solve this without hard coding.SolutionHello, As mentioned, the resistance of material decreases as the intensity of light falling on it decreases.Hen

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site