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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Define the finite element Function through a loop

sfan
1-Visitor

Define the finite element Function through a loop

Hi, everyone,

I am trying to construct the finite element function through a loop since the function is split into parts according to the number of elements.

In the attachment I define uh(x) as the approximating function which follows:

for each element,

uh(x)=a*N1(xi)+b*N2(xi)+c*N3(xi),

where a, b, c are the nodal values read from the u vector constructed.

N(xi) is the defined function where xi ranges from -1 to 1.

A mapping from x to xi is also defined in the loop (xi=2*x*NumELE-(2*i-1)), as xi is for each local domain and x is for the global.

When I test the function with a value of x, Mathcad suggests that it can only be performed on an array,

is there a way to construct such kind of piece-wise function through for-loop?

Looking forward to your help!

Thank you

Shawn

ACCEPTED SOLUTION

Accepted Solutions
Fred_Kohlhepp
23-Emerald I
(To:sfan)

Your function u(_h(x)contains a loop, for i . . .

This led me to assume that you wanted to ervaluate four answers--one for each pass thru the loop. So I changed your coding to collect the value each time in the vector temp and return all of them.

If you only want the first one, why execute the loop?

At any rate, it's easy to return only the first (or only the second, or only the third,) just return only the element you want.

View solution in original post

4 REPLIES 4
Fred_Kohlhepp
23-Emerald I
(To:sfan)

You define a vector u.

Immediately underneath it you define a function u of a range variable x.

Chaange the name of the function u(x) and your u_h(x) function can be made to work.

Hi, Fred,

Thanks for your quick reply,

you have been helping us since I used the 15 version.

But now the uh(x) turns out to be a vector, as uh(1/4) gives a results of vector with four values while it should equals to 0.074, which is the first component of that vector.

How I am able to define a piecewise function of x thru the loop?

Looking forward to your help.

Best

Shawn

Fred_Kohlhepp
23-Emerald I
(To:sfan)

Your function u(_h(x)contains a loop, for i . . .

This led me to assume that you wanted to ervaluate four answers--one for each pass thru the loop. So I changed your coding to collect the value each time in the vector temp and return all of them.

If you only want the first one, why execute the loop?

At any rate, it's easy to return only the first (or only the second, or only the third,) just return only the element you want.

Thank you Fred,

That's really helpful!

Announcements

Top Tags