Filter löschen
Filter löschen

help with managing data

7 Ansichten (letzte 30 Tage)
francis
francis am 11 Jul. 2013
this is the problem
and I have been working on it and this is what I got %Problem 4.19 t=200:20:400; a=[38.91;48.50;29.10;29.00]; b=[3.904E-2;9.188E-2;1.158E-2;0.2199E-2]; c=[-3.105E-5;-8.540E-5;-0.6076E-5;-0.5723E-5]; d=[8.606E-9;32.40E-9;1.311E-9;-2.871E-9]; c_p=a+b.*t+c.*t.^2+d.*t.^3
and it tells me matrix dimensions must agree , I dont know what to do , if you can please give me some tips on how to do it , I have multiple exersices like this and I want to get the idea

Antworten (1)

Cedric
Cedric am 11 Jul. 2013
Bearbeitet: Cedric am 11 Jul. 2013
Using the command WHOS in your command window, you get
>> whos
Name Size Bytes Class Attributes
a 4x1 32 double
b 4x1 32 double
c 4x1 32 double
d 4x1 32 double
t 1x11 88 double
Which shoes that in the following
c_p = a + b.*t + c.*t.^2 + d.*t.^3
you are trying to multiply element-wise e.g. b which is a 4x1 array (a column vector) and t which is a 1x11 array (a row vector). This is not a valid operation.
There are several approaches for solving this, the simplest being a basic FOR loop in which e.g. ti could be element i of vector t, and you would deal with ti in your equation and store the result in an array of c_p's.
(a more complicated approach could be based on BSXFUN, but I don't recommend it if you are just starting MATLAB).
  2 Kommentare
francis
francis am 11 Jul. 2013
I am sorry but I dont understand I been trying to figure out, I have to make a matrix of 11X5 with all the results ,I am very thankful for any input you can provide me
Cedric
Cedric am 12 Jul. 2013
Bearbeitet: Cedric am 12 Jul. 2013
b.*t
is an element-wise multiplication. Imagine that b=[2,3,4]; there are two valid cases for such an operation:
1. t is a scalar, e.g. t=8, and
b.*t = [2,3,4].*8 = [2*8,3*8,4*8] = [16,24,32]
2. t has same dimension as b, e.g. t=[10,11,12], and
b.*t = [2,3,4].*[10,11,12] = [2*10,3*11,4*12] = [20,33,48]
If t is any other size, the element-wise multiplication .* is not defined.
One way to solve the equation for each value of t is to loop over all elements of t, as each one of them is a scalar, and solve the equation in the loop, saving the result in an array.
The only additional help that I can provide without giving you the answer is a link to the official documentation: http://www.mathworks.com/help/pdf_doc/allpdf.html. You will find there relevant PDFs for learning MATLAB basics, among which, under "MATLAB", documents called "MATLAB Primer", "Mathematics", and "Programming Fundamentals". Spending an hour on the primer will certainly allow you to answer your question.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by