MATLAB fails to display plot, but Microsoft Excel can - excel

My goal is to recreate a plot in Excel in MATLAB. In excel, I have coded:
1/(1 + (SINH($B$4^(1/2)*(1 - C6)^(1/2)))^2/(4*C6*(1-C6)))
In the above, cell B4 has the value 10. C6 through C500 take values starting at 0 upto 5 in succession (so C6 would be 0, and C500 would be C6+0.01+0.01+0.01... = 5), with increments of 0.01.
In other words, the column 'C' runs from 0 to 5 in increments of 0.01 (which is the x axis of the plot). I then apply the above formula to column C to obtain the graph below.
Excel displays the following, which is correct:
However, attempting to recreate the same graph in MATLAB results in an empty plot (which I show after the code)
v = 10
x = [0:0.01:5]
plot(x, 1/(1 + (sinh(v^(1/2)*(1 - x).^(1/2))).^2/(4*x.*(1-x))), 'LineWidth', 2)
grid on
xlabel('x')
ylabel('Transmittance')
I have tried restarting my computer, restarting MATLAB to no avail.
Thanks for your guidance!

You forgot two .'s:
1./(1 + (sinh(v^(1/2)*(1 - x).^(1/2))).^2./(4*x.*(1-x)))
^ ^
I advise you to first evaluate the expression and store in a varable, then you can immediately see that without this dot you will a single value. Plotting a vector and a single value doesn't really produce anything usable, but also does not throw an error, so it's tricky to debug without having the variable in the workspace.

Related

what does E represent in microsoft Excel?

Excel has just output this trendline: y = 0.032x4 - 5608.x3 + 4E+08x2 - 1E+13x + 1E+17
How can I convert this equation into a useable form without the E's.
(how do you interpret these E's)
You can use the trendline from a graph in an equation, but, in addition to translating it correctly, you need to also format the trendline to show a maximum number of decimals (e.g 15), else your results will not be congruent with the graph.
Your formula would translate into something like:
y = 0.032*(x^4) - 5608*(x^3) + 4E+08*(x^2) + 1E+13*(x) + 1E+17
4E+08 will be interpreted by Excel as being 4*10^8 or 400,000,000. You don't have to do that yourself,
However, unless you have a very old version of Excel, where the LINEST function did not work properly, it is usually simpler to just use worksheet functions for that purpose.
For example, if this is a line graph where y is your range of y-values; your trendline is a 4th order polynomial, and your x-axis is just serial numbers 1..n, you could use:
=LINEST($A$4:$A$12,SEQUENCE(COUNT(y))^{1,2,3,4})
to return your sequence of m values.
And to return a point along the curve, you could use
=SUM(LINEST($A$4:$A$12,SEQUENCE(COUNT(y))^{1,2,3,4})*A4^{4,3,2,1,0})
where A4 represents a new_x value.
If you don't have the SEQUENCE function, there are a variety of other functions that can be used to generate a sequence of values; or you can just select your known_x's (which you would have to do anyway if they are not sequential {1..n})
The Scientific format displays a number in exponential notation,
replacing part of the number with E+n, in which E (exponent)
multiplies the preceding number by 10 to the nth power. For example, a
2-decimal scientific format displays 12345678901 as 1.23E+10, which is
1.23 times 10 to the 10th power.
Before
y = 0.032x4 - 5608.x3 + 4E+08x2 - 1E+13x + 1E+17
After
y = 0.032x4 - 5608.x3 + 4 x 10^8x * 2 - 1 * 10^13x + 1 * 10^17
Basically really large numbers,4 x 10^8x*2=400000000x*2, 1 x 10^13x=10000000000000x, 1E+17=100000000000000000

How to calculate with the Poisson-Distribution in Matlab?

I’ve used Excel in the past but the calculations including the Poisson-Distribution took a while, that’s why I switched to SQL. Soon I’ve recognized that SQL might not be a proper solution to deal with statistical issues. Finally I’ve decided to switch to Matlab but I’m not used to it at all, my problem Is the following:
I’ve imported a .csv-table and have two columns with values, let’s say A and B (110 x 1 double)
These values both are the input values for my Poisson-calculations. Since I wanna calculate for at least the first 20 events, I’ve created a variable z=1:20.
When I now calculated let’s say
New = Poisspdf(z,A),
it says something like non-scalar arguments must match in size.
Z only has 20 records but A and l both have 110 records. So I’ve expanded Z= 1:110 and transposed it:
Znew = Z.
When I now try to execute the actual calculation:
Results = Poisspdf(Znew,A).*Poisspdf(Znew,B)
I always get only a 100x1 Vector but what I want is a matrix that is 20x20 for each record of A and B (based on my actual choice of z=1:20, I only changed to z=1:110 because Matlab told that they need to match in size).
So in this 20x20 Matrix there should always be in each cell the result of a slightly different calculation (Poisspdf(Znew,A).*Poisspdf(Znew,B)).
For example in the first cell (1,1) I want to have the result of
Poisspdf(0,value of A).*Poisspdf(0,value of B),
in cell(1,2): Poisspdf(0,value of A).*Poisspdf(1,value of B),
in cell(2,1): Poisspdf(1,value of A).*Poisspdf(0,value of B),
and so on...assuming that it’s in the Format cell(row, column)
Finally I want to sum up certain parts of each 20x20 matrix and show the result of the summed up parts in new columns.
Is there anybody able to help? Many thanks!
EDIT:
Poisson Matrix in Excel
In Excel there is Poisson-function: POISSON(x, μ, FALSE) = probability density function value f(x) at the value x for the Poisson distribution with mean μ.
In e.g. cell AD313 in the table above there is the following calculation:
=POISSON(0;first value of A;FALSE)*POISSON(0;first value of B;FALSE)
, in cell AD314
=POISSON(1;first value of A;FALSE)*POISSON(0;first value of B;FALSE)
, in cell AE313
=POISSON(0;first value of A;FALSE)*POISSON(1;first value of B;FALSE)
, and so on.
I am not sure if I completely understand your question. I wrote this code that might help you:
clear; clc
% These are the lambdas parameters for the Poisson distribution
lambdaA = 100;
lambdaB = 200;
% Generating Poisson data here
A = poissrnd(lambdaA,110,1);
B = poissrnd(lambdaB,110,1);
% Get the first 20 samples
zA = A(1:20);
zB = B(1:20);
% Perform the calculation
results = repmat(poisspdf(zA,lambdaA),1,20) .* repmat(poisspdf(zB,lambdaB)',20,1);
% Sum
sumFinal = sum(results,2);
Let me know if this is what you were trying to do.

Excel Equation of line not correct

I'm hoping someone will be able to tell me why the equation that Excel generated is not giving the correct results as it is graphed correctly.
I have some X and Y points that I will list below. I plotted those points in Excel and then plotted the trend line, and had it show me the equation of the trendline. When I take the equation and then plug in the X values I get very different answers back.
X and Y Values
X Y
0 3
3 2
5 1.4
7 1
10 0.5
18 0.1
When I set the intercept to 3, the equation of the trendline is y = 0.0088x5 - 0.1457x4 + 0.8753x3 - 2.224x2 + 1.4798x + 3
Screenshot of Excel window with equation
Any help is greatly appreciated.
I suspect you didn't set up your graph correctly.
Select a single cell in your table
Insert/Scatter (and decide which you want with regard to markers, etc)
Select the line and add Trendline
Set you parameters for the trendline
If you want to get the formula for the trendline from the "show formula" option, be sure to format the trendline label to be numeric with 15 decimals. Otherwise the equation will certainly not work, even if it appears to be correct.
Note that you can obtain the formula directly using the LINEST worksheet function.
=LINEST(Y,X^{1,2,3,4,5}) returns the array:
{0.0000399230399230442,-0.00152188552188569,0.0192991822991846,-0.0840134680134806,-0.217128427128402,2.99999999999999}
The last value in the array is the y-intercept
The slight differences are due to the use of different algorithms for the two methods.

charting trendlines together

I need to display this kind of data in one chart:
Which means:
Function A: Y= X + 10 ;
Function B: Y= X * 2 ;
but what I got from excel is:
Actually what I want is (sorry for the drawing):
My real data is like:
If I format it like this:
I can still not get the correct charts.
Updated to account for change of question
Your data structure is wrong to achieve this in Excel, see for example:
On the left you want your x axis values, don't put a header in this column otherwise it will plotted on your graph as a series (extra line).
You can fill in gaps in your data with #N/A and excel will ignore these points, joining the line to the next available point.

Creation of vector of unknown size in Excel

I am attempting to translate my existing Matlab code into Numbers (basically Excel). In Matlab, I have the following code:
clear all; clc;
n = 30
x = 1:(n-1)
T = 295;
D = T./(n-x)
E = T/n
for i=1:(n-2)
C(i) = D(i+1) - D(i)
end
hold on
plot(x(1:end-1), C, 'rx')
plot(x, D, 'bx')
I believe everything has been solved by your formulas, there are parts of them that I don't understand otherwise I would try to figure the rest out myself. Attached is the result (Also you might like to know that the formulas you gave work and are recognized in Numbers). Im trying to figure out why (x) begins at 2 as I feel as though it should start at 1?
Also it is clear that the realistic results for the formulas only exist under certain conditions i.e. column E > 0. That being the case, what would be the easiest way to chart data with a filter so that only certain data is charted?
(Using Excel...)
Suppose you put your input values T & n in A1 & B1 respectively.
You could generate x, D & C In columns C,D & E with:
C1: =IF(ROW()<$A$1,ROW(),"")
D1: =IF(LEN(C1)>0,$A$2/($A$1-C1),"")
E1: =IF(LEN(D2)>0,D2-D1,"")
You could then pull all 3 columns down as far as you need to generate the full length of your vectors. If you then want to chart these, simply use these columns as inputs.

Resources