Computing vectors using a square n by n matrix. Seems easy but is tricking me.
1 回表示 (過去 30 日間)
古いコメントを表示
I am given a square n by n matrix A , a column vector v of n entries, and a vector c with entries c1,c2,c3,....ck, I am wanting to compute this column vector:
w = (c1I + c2A + c3A^2 + .....+ ckA^(k-1))v
Using four different ways (and I assume to use tic toc if I want to compare their lengths of time in computation).
1) Compute the matrix B = c1I + c2A + c3A^2....ckA^k-1 by successively computing A^2 , A^3, etc and adding them and then computing w = Bv
2) I want to modify part (i) by computing successively _A^2 = A(A),A^3 = A(A^2), A^4 = A(A^3), etc.
3) I know that when incorporating vector v by expansion I'll get w = (c1I + c2A + c3A^2 + .....+ ckA^(k-1))v but I want to evaluate this from left to right by computing Av = A(v), A^2v = A(Av), A^3v = A(A^2v)....
4) Using Horner's method, I want to rewrite the last expression in part 3 as: w = c1v + A(c2 + A(c3v + ....+A(c(subk-1)v + A(ckv)) *Note I know this expression can be evaluated left from right by noting this pattern: multiply by A then add civ.
I do not get how to write some of these vectors in matlab and essentially how to go about doing this. Thorough explanation would save me so much and aid me in computing further problems I would like to learn and investigate without needing the help of a website
2 件のコメント
Sean de Wolski
2012 年 4 月 17 日
A good place to start:
http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
回答 (1 件)
Geoff
2012 年 4 月 18 日
There really are no shortcuts in learning how to think in computer-speak. Your real learning happens when you sit down and try things out. You can ask questions of the community, but if the answer is that there's a web page that explains concepts better than anything else, you should read that web page.
I say again: try things out! Experiment. Construct a simple test case where you know what the result will be. Try to write code that achieves that result. Try to validate any intermediate steps that need to be taken in achieving it. It's no good fretting about the final result of 10 computing steps being wrong if you don't realise that you made an error in step 2.
So work out a simple case that you can easily verify. Build your matrices, start trying things... The fastest learning happens by doing. Maybe with the odd nudge along the way.
Here's a nudge...
A^0 is equal to I
A^1 is equal to A
...
The exponent (on the right-hand side of ^) can be a variable.
The exponent and the value you select from c for each term in the equation are directly related.
You can use a loop to add up successive calculations into one variable.
w = 0;
for n = 1:something
whatever = somecalculation;
w = w + whatever;
end
% maybe there's something you want to do with w after the loop...
You can put a breakpoint (F12) in your loop on the line whatever = somecalculation, then when you run your program the execution will be interrupted before running that line of code. Press F10 to 'step': That is, run the line and pause again. Now you can hover your mouse cursor over 'whatever' and check its value is correct. You can even use 'whatever' in the command window and do stuff with it. Plot it... whatever. Press F5 to run your script from the point it left off. It will only stop when it finishes or if it hits your breakpoint again. This is called 'debugging'. It's very helpful in checking your intermediate results.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!