4951 Shares

Topic: **How to write a program in matlab****Question:**
I am fitting a 2nd order regression curve to some data ussing a least squares method and finding the required co-efficents, m-file polyregr2.m which works fine...
Now I'm trying to visualise this fit ussing with a second m-file (plotreg.m) wich I want to pull all the data from polyregr2.m to complete the m-file file I wrote is shown;
polyregr2(T,v);
t = min(T):0.05:max(T);
m = size(t,2);
for i = 1:m
f(i) = a(n+1);
for j = n:-1:1;
f(i) = a(j) + f(i)*t(i);
end
end
plot(t,f,'r--')
hold on
plot(v, T, 's')
Now when I put all this in an error saying I haven't defined any of the co-efficents comes up when it should have got it from poleregr2.m how can I make this happen?
In polyreg2r.m I have defined T,v and n

April 19, 2019 / By Orson

u call polyregr2(T,v); whitout giving values to T and v edit doesnt poluregr2 needs a input for work? if no give it some outputs and do [T v n]=poliregr2; poliregr2 need to have a output in the *.m file note every time u get out of a function it reset all the variables (unless they are global or they are returned)

👍 264 | 👎 8

Did you like the answer? We found more questions related to the topic: **How to write a program in matlab**

My first bit of advice would be to scrap your current method and store your form data in a MySQL database. However, if that solution isn't available to you, then you've pretty much already solved your own problem. As you've pointed out, the team_roster.html page needs to be able to read/parse the data out of the file that you write to when you submit the form. For that to happen, it needs to be a .php file so that you can use PHP code inside of it. So...why not just make that file a .php file? Then, you can include the parsing code that you need and output the result on to the page. Having said that, you could also just write roster.php such that it re-creates your team_roster.html page from scratch each time a new entry is added. That way, roster.php is responsible for both reading in the data from the form and then using that data directly to write to the team_roster.html page. Once again though...seriously...use a database, and if you're going to be working with dynamic information, (such as a constantly updating user roster), just make all of your pages .php...it won't hurt anything if all that's in them in HTML, and it'll make it possible for you to add program code when you need to.

The PHP doesn't need to write to another document, just have the PHP file send HTML code to the user. For example, if you are POSTing the variables firstname and lastname, just put this in roster.php:

Hello! Your first name is and your last name is .

If you're using GET instead of POST, just substitute POST with GET in the above code. But wait, it sounds like you want the data people submit to be saved later so that it always exists. So say you have rosteroutput.txt with everyone's first and last names in it. You want to create a PHP document, NOT an HTML document, that will return the contents of the file. Remember, you can send HTML code to the client from a PHP file. As a matter of fact, you could just have a document team_roster.php that says: That would send the entire text document to the person viewing the website. If you had it so that the text document had HTML in it, this is all you would need to do.get a Gmail account, i think of you are able to shop as much as 512 MB of information in one e mail basically deliver the document to your self then log in with the different computing device to the account and save teh document from your self.

👍 110 | 👎 6

A quadratic has one or more imaginary root if sqrt(b^2 - 4ac) does not exist, meaning the discriminant (b^2 - 4ac) is negative. If the program finds the discriminant is negative, throw up that warning. If it finds that it's positive, calculate it and throw up the answers.

a) Solve by factorising x2 - 6x + 8 = 0 Break up the 8 into its factors, and then identify two which add to give -6 and multiply to give 8. You should get -2 and -4. Therefore, (x-2)(x-4) = 0 --- ab = 0, a=0 or b=0 x= 2 or 4. --------------------------- b) Solve using the quadratic formula. x= [-b±√(b2 - 4ac)] / 2a in x2 - 6x + 8 = 0, a = 1, b = -6 and c = 8 x = [6±√(36-32)] / 2 x = [6±2]/2 x = 2 or 4 --------------------------- 2) For the function y = x2 - 6x + 8, perform the following tasks: a) Put the function in the form y = a(x - h)2 + k. This involves completing the square. y = x2 - 6x + 8 y = x2 - 6x + 9 - 1 y = (x-3)2-1 ---------------------------- b) What is the equation for the line of symmetry for the graph of this function? From part (a), the equation for the line of symmetry is x=h, therefore x = 3 ---------------------------- c) [Graph] It is not necessary to plot points, as you can find the equation of the line of symmetry, the vertex or turning point and intercepts very easily. ---------------------------- d) The graph has the same shape, but is shifted 1 unit down, and 3 units to the right. ---------------------------- 3) You're given the general equation and all the variables, so just pop them in and you get: s = -16t2 + 32t --------------------------- b) Sub in t=1, s = -16(1)2+32(1) = 16ft. --------------------------- c) When it hits the ground, the s = 0. 0 = -16t2 + 32t 0 = t2 - 2t 0 = t(t-2) t = 0 or 2 seconds. Discarding the 0 solution, we get t = 2 seconds. ---------------------------- d) the maximum height is halfway between launch and hitting the ground, at t = 1 second. You can use the answer from b, 16ft. ----------------------------------- 4) The equation for the perimeter is: 2(l+w) = 400ft. l + w = 200ft. l = 200 - w. The equation for the area is A = l x w. sub in (200-w) for l, A = w(200-w) A = - w2 + 200w We have to find the turning (maximum) point. The equation for the line of symmetry is -b/2a = -200/-2 = 100 Therefore at the max, w = 100ft and l = 200-100 = 100ft. The area here is 10,000 ft2.

If you have your own answer to the question how to write a program in matlab, then you can write your own version, using the form below for an extended answer.