Trying to solve:
T = 6.11^(5400((1/273)-(1/T)))
where:
T =[273, 283, 293, 303]
Can't seem to get the syntax down. Any help would really be appreciated!
T is a matrix, so if you try just defining T and entering it into the equation, you're going to be doing a lot of matrix math you probably don't intend. As #Sardar mentioned in his comment, to instead do vectorized operations on all of the values in parallel, you want to use the elementwise, or 'dot', versions of multiplication, division, and exponential operators. See https://octave.org/doc/latest/Arithmetic-Ops.html
Note also that you can't use parentheses as implied multiplication, you need a *
Then you should get the following:
>> T =[273, 283, 293, 303];
>> T = 6.11.^(5400.*((1/273)-(1./T)))
T =
1.0000 3.5432 11.5160 34.6268
Also note that reusing T like this overwrites your input vales with the output values of T. Be sure that's what you want to do.
Related
I'm trying to solve a one order differential equation with variable coefficients of the following form:
xdot(1)=a(t)*x(1)+b;
where b=a constant and where a(t) = a time dependent function. I know that I can solve this equation by hand butt a(t) is a quite complex function.
So, my problem is the following. a(t) is a function which I know its values from an experiment (I've got all the results in a file) --> a(t) is a vector (n x 1) which is a problem because x(1)= xdot(1)=a scalar. So, how could I solve this equation, with lsode ?
Possibly I have underestimated your problem, but the way I read it, you are asking to integrate a first order ODE. In general there are two ways to proceed,, implicit methods and explicit methods. Here is the crudest, but easiest to understand, method I can come up with:
nt=101;a=-ones(1,nt);b=1/2;x=NaN*ones(1,nt);x(1)=pi;dt=0.01;
for kt=2:nt
dxdt=a(kt-1)*x(kt-1)+b;
x(kt)=x(kt-1)+dxdt*dt;
endfor
plot(x)
I have assumed a<0 so there is no tendency to blow up. You will want to set it equal to your observed values.
I'm relatively new to Scilab and I would like to find the indices of a number in my matrix.
I have defined my number as maximal deformation (MaxEYY) and on displaying it, it is correct (I can double check in my *.csv file). However, when I want to know exactly where this number lies in my matrix using the find command, only (1,1) is returned, but I know for a fact that this number is located at (4,8).
My matrix is not huge (4x18) and I know that this number only occurs once. On opening the *.csv file, I removed the headers so there is no text.
Can anyone help me with this?
N=csvRead("file.csv",",",".",[],[],[],[],1)
EYY=N(:,8);
MaxEYY=max(EYY);
MinEYY=min(EYY);
[a,b]=find(MaxEYY);
disp([a,b]);
First, you need to understand how find() works: it looks for values of true or false in a matrix. So if you want to find a certain value in it, you should do find(value == matrix).
Then, notice that in your code, you are applying find() to MaxEYY, which is a single value, that is, a scalar, a 1-by-1 matrix. When you do that, you can only get (1,1) or [] as results.
Now, combining these two informations, this what you should've done:
[a, b] = find(EYY == MaxEYY);
Also, there is a quicker way to get this indices: max() can also return the indices of the maximum value by doing
[MaxEYY, inds] = max(EYY);
And the same goes for min().
I can get maxima to solve an equation but can't figure out why it won't show it's numerical value without typing the extra command/step of float(%). Is there away to automatically convert a solved variable to a numerical format.
Example of equation below:
kill(all); alpha:float(.0014931); endfreq:50; dursec:1200; solve(alpha=log(startfreq/endfreq)/dursec,float(startfreq));
what comes back is
startfreq=50%e(44793/25000)
I would like it to say 299.988 instead
Well, Maxima prefers exact results (i.e., integers, rational numbers, and symbolic constants) instead of inexact (i.e., float and bigfloat numbers). If you want to work only with numerical solutions, take a look at find_root. E.g.:
(%i1) [alpha, endfreq, dursec] : [0.0014931, 50, 1200] $
(%i2) find_root (alpha = log(startfreq / endfreq)/dursec, startfreq, 1, 500);
(%o2) 299.9881594652534
Note that to use find_root you must know an interval (here 1 to 500) which contains a root of the equation.
equation1:
solve({a^2+b^2+169+sqrt(c-13)-24*a-10*b = 0},{a, b, c})
assuming a>0, b>0, c>0;
//a=12, b=5, c=13
equation2:
solve([1/(cos(a)^2)+1/(sin(a)^2*sin(b)^2*cos(b)^2) = 9,
a>0, a<Pi/2, b>0, b<Pi/2], [a,b,c] );
//a=arctan(sqrt(2)), b=Pi/4
I have tired above, but maple couldn't gives a solutions, Am I using solve incorrectly?
In (Eq. 1) it's not your syntax that's an issue. You have three unknowns {a,b,c} but only one equation. You simply do not have enough equations to determine {a,b,c} uniquely. Maple's solve function only returns an answer (if possible) if the number of variables equals the number of equations.
In (Eq. 2) you use square brackets, which are used for ordered lists. The solve function requires a set of equations, which are indicated by curly braces. Again, you have three variables but only one equation. Same problem.
If the equations are linear (which they aren't in your case), Maple can find a parameterization for the solutions in the case of an underdetermined system: http://www.maplesoft.com/support/help/Maple/view.aspx?path=solve/linear.
I need to write my own function which has the form f(x,y)=Integrate(g(x,y,z),z from 0 to inf). so the code I used was:
function y=f(x,y)
g=#(z)exp(-z.^2)./(z.^x).*(z.^2+y.^2).^(x/2);% as a function of x,y and z
y=quadgk(g,0,inf)
and if I call it for a single value like f(x0,y0), it works but if I try to calculate something like f([1:10],y0), then the error message says that there is something wrong with the times and dimension. In principle I can use for loops but then my code slows down and takes forever. Is there any help I can get from you guys? or references?
I'm trying to avoid the for loop since in matlab it's much faster to use matrix computation than to use for loop. I wonder if there is any trick that I can take advantage of this feature.
Thanks for any help in advance,
Lynn
Perhaps you can try to transpose the interval, creating row based values instead of column based f([1:10]',y0). Otherwise something in your function might be wrong, for example to get x^y to work with lists as input, you have to prefix with a dot x.^y. The same for mulitply and division I think..
If loop is no problem for you, you should do something like:
function y2=f(x,y)
y2=zeros(size(x));
for n=1:numel(x)
g=#(z)exp(-z.^2)./(z.^x(n)).*(z.^2+y.^2).^(x(n)/2);% as a function of x,y and z
y2(n)=quadgk(g,0,inf)
end
The problem here is that quadk itself uses vectors as argument for g. Then you have in g somethink like z.^x, which is the power of two vectors that is only defined if z and x have the same dimension. But this is not what you want.
I assume that you want to evaluate the function for all arguments in x and that the output vector has the same dimension as x. But this does not seem to be possible since even this simple example
g=#(x)[x;x.^2]
quad(g,0,1)
does not work:
Error using quad (line 79)
The integrand function must return an output vector of the same length as the
input vector.
A similar error shows when using quadgk. The documentation also says that this routine works only for scalar functions and this is not surprising since an adaptive quadrature rule would in general use different points for each function to evaluate the integral.
You have to use quadvinstead, which can integrate vector valued functions. But this gives wrong results since your function is integrated in the interval [0,\infty).