cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

12-Amethyst

## Problem with vectors

Hi all,

I have a function with 6 loops (0 to 5), but when I try to keep track of changes of two parameters (alpha and betta), they are returned as the last members of two 1by12 vectors. The numbers of my data sets (x and y) are exactly 12, but I dont know what is the relationship between the these two. I wonder if somebody could take a look at it?Best,

Physical Mathematics

1 ACCEPTED SOLUTION

Accepted Solutions
23-Emerald II
(To:mzarrabi)

Ok,

there's a lot more not in order.

In your function f.trial there's a big For-loop, with i as a running variable.

Within that For-loop you have twice an assigment to a variable called J where the rhs is a comnpound statement. In that compound statement there's another nested set of For-loops using j and also (again) i as running variables. That is a guarantee for interference with the outer For-loop. So you are definitely not getting what you hoped to get, or you must be very lucky.

Also, that the nested for loop runs on both i and j, but does not use them, there is nothing within the inner For-loop that depends on either i or j. It repeats the VERY same statement (assigning something to the first two columns of J) over and over again. So this too is doing something other than what you intended.

A minor improvement can be achieved: in between the two assignments to J there's an IF statement with an Otherwise. Inside the Otherwise you unnecessarily assign alpha to alpha and beta to beta, while you (probably) only need to double lambda.

I've stopped looking further.

We may be able to help you if you explain what the problem is you are trying to solve with this function. It would surely help to break it apart in multiple functions, where one function calls another {I think that the assignment to J could be done with a separate function that you then call twice. And I would set the now embedded function L.2(J) apart.}. That way the functionality of each part can be tested easily, and the f.trial becomes smaller for better overview.

Success!

Luc

4 REPLIES 4
23-Emerald II
(To:mzarrabi)

You're using a variable named lambda, somewhere around midway of the Ftrial function, while assigning to A. This lambda is undefined.

Success!
Luc

12-Amethyst
(To:LucMeekes)

Thank you for your response. I've corrected the worksheet (see attached), but the problem is not related to lambda.

Best,

23-Emerald II
(To:mzarrabi)

Ok,

there's a lot more not in order.

In your function f.trial there's a big For-loop, with i as a running variable.

Within that For-loop you have twice an assigment to a variable called J where the rhs is a comnpound statement. In that compound statement there's another nested set of For-loops using j and also (again) i as running variables. That is a guarantee for interference with the outer For-loop. So you are definitely not getting what you hoped to get, or you must be very lucky.

Also, that the nested for loop runs on both i and j, but does not use them, there is nothing within the inner For-loop that depends on either i or j. It repeats the VERY same statement (assigning something to the first two columns of J) over and over again. So this too is doing something other than what you intended.

A minor improvement can be achieved: in between the two assignments to J there's an IF statement with an Otherwise. Inside the Otherwise you unnecessarily assign alpha to alpha and beta to beta, while you (probably) only need to double lambda.

I've stopped looking further.

We may be able to help you if you explain what the problem is you are trying to solve with this function. It would surely help to break it apart in multiple functions, where one function calls another {I think that the assignment to J could be done with a separate function that you then call twice. And I would set the now embedded function L.2(J) apart.}. That way the functionality of each part can be tested easily, and the f.trial becomes smaller for better overview.

Success!

Luc

12-Amethyst
(To:LucMeekes)

Thank you @LucMeekes for your time and looking at my worksheet. Your comments are valuable. As you said, my worksheet needs more corrections, and I am currently working on it. However, my major problem was solved by changing i to k in the main for loop and Pi and Qi to Pk and Qk correspondingly. I think Mathcad mistook different loops together. Best,

Announcements
Check out the latest