Regarding the vectors calculation
2 Kommentare
Antworten (1)
Hi @yogeshwari patel ,
Please see my response to your comments below.
- My query is u_exact is an array . How it is consider as array .*
In MATLAB, arrays can be either row or column vectors, or multidimensional matrices. In your code snippet:
x = 0:0.1:1; t = 0.5; u_exact = sin(x) .* exp(-t);
The variable x is defined as a row vector ranging from 0 to 1 with increments of 0.1 which results in 11 elements.
x = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]`.
If you notice in my attached file, the expression sin(x) .* exp(-t) computes the sine of each element in x and multiplies it by exp(-t), which is a scalar value (approximately 0.6065). The result is also a row vector because MATLAB performs element-wise operations on arrays of compatible sizes.
Therefore, u_exact becomes:
u_exact = [0, 0.0606, 0.1205, 0.1792, 0.2362, 0.2908, 0.3425, 0.3907, 0.4351, 0.4751, 0.5104], which has a size of 1x11 (one row and eleven columns).
- One more query why size of the array is 1 x 80 why it is not 1 X 11*
Regarding your query about the size of the array being reported as 1x80, it appears there may have been a misunderstanding or miscommunication: When you execute the command `fprintf('The size of u_exact is: %dx%d\n', size(u_exact)); , it should correctly output:
The size of u_exact is: 1x11 (this is what @DGM trying to tell you)
For more information on function “size”, please refer to
https://www.mathworks.com/help/matlab/ref/size.html
Now, in your case, since you mentioned seeing a size of 1x80, it could indicate that either the variable has been inadvertently modified somewhere else in your code to include more elements and not being shared with us in your posted comments or you performed a previous computation that expanded u_exact into a larger array.
Please see attached.
Hope this answers your question, please let us know if you have any further questions.
0 Kommentare
Siehe auch
Kategorien
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!