Matlab problem with writing equations
i am having problem with writing equations.
r = 25, k= 2, R = 50:25:600, DR = 0.5:0.5:4.0
开发者_StackOverflow社区h= r*[1-cos(asin((sqrt(2*R*DR+DR^2))+r*sin(acos(r-k)/r)/r))]-k
but as a resault i get this: h = 1.9118e+001 +1.7545e+002i.
I just start with Matlab. Thanks
What I get from what you've written is actually
??? Error using ==> mtimes
Inner matrix dimensions must agree.
which is correct because you're trying to multiply two row vectors by one another. Could you please show us the actual code you used?
Anyway, supposing that's dealt with somehow, it looks to me as if you're feeding something to asin
that's much bigger than 1. That'll give you complex results. Is the thing you're passing to asin
perhaps meant to be divided by R^2
or DR^2
or something of the kind? You have a similar issue a bit later with the argument to acos
.
I also suspect that some of your *
and ^
and /
operators should actually be elementwise ones .*
, .^
, ./
.
If you're trying to do as you said:
so in first equation i used R= 50, DR = 0.5, r= 25, k=2 and i need to get h. In second equation i used R=75, DR=1.0, r=25, k=2...for a last equation i used R=600,DR=4.0,r=25,k=2.
DR and R need to be the same length... so if R goes between 50 and 600 in increments of 25, DR should go from 0.5 to 12.5 in increments of 0.5, or 0.5 to 4.0 in increments of 0.1522...
once you figure that out, be sure the add a period before every matrix multiplication operation (e.g. * or ^)
EDIT: formula adjusted slightly (bracketing) to reflect success in comment.
When you say you want a table, I guess it is to be an R
by DR
table (since you have to vectors of different length). To do that you need to use R
as a column vector (R'
below) and multiply with *
(not .*
). When R
doesn't appear in a term multiply by ones(size(R))
(or use repmat
) to get DR into the right shape. To square DR
by element, you need DR.^2
. There seems to be a misplaced bracket for the acos
, surely you divide by r
before taking the acos
. There must be a division by something like r
in the asin
(not r^2
because you've taken the sqrt
). Finally, the last division by r
is redundant as written, since you multiply by r
at the same level just before. Anyway, if I do the following:
h= r*(1-cos(asin((sqrt(2*R'*DR+ones(size(R))'*DR.^2)/r)+sin(acos((r-k)/r)))))-k
I get an R
by DR
table. Results for small R,DR
are real; higher R,DR
are complex due to the argument of the first asin
being >1. The first entry in the table is 4.56, as you require.
精彩评论