# Nodal basis function 1D

Hello all, I coded a nodal basis function for 1D element from [-1,1]. the code is below:

`close all; clc; clearvars;n=10;x = linspace(-1,1,n);for i=1:n   a= x(i);   for j=1:n       b(j)=a.^(j-1);          end  v(i,:)=b';endvinv=inv(v);for i=1:n k=zeros(1,n); k(i)=1; f=vinv*k'p(:,i)=f; end for i=1:n        g=@(x) p(1,i)+p(2,i).*x+p(3,i).*x.^2+p(4,i).*x.^3+p(5,i).*x.^4+p(6,i).*x.^5+p(7,i).*x.^6+p(8,i).*x.^7+p(9,i).*x.^8+ ....        p(10,i).*x.^9;legendInfo{i} = ['Phi ' num2str(i)]; fplot(g, [-1 1])legend(legendInfo)       hold on;end`

The code works already but my problem is in last “for loop” where I calculated “g” as a function handle. I want to instead of adding the terms from 1 to 10, use an automated calculation. Now, if I want to change number of nodes (n) from 10 to 20 I have to add 10 additional terms by hand. Moreover, Does somebody knows a better way to calculate nodal basis function for 1D element?

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

`n=10;x = linspace(-1,1,n);for i=1:n    a= x(i);    for j=1:n        b(j)=a.^(j-1);    end    v(i,:)=b';endvinv=inv(v);for i=1:n    k=zeros(1,n);    k(i)=1;    f=vinv*k'    p(:,i)=f;endx = linspace(-1,1,1000) ;for i=1:n`

--

--

## More from Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

Love podcasts or audiobooks? Learn on the go with our new app.

## Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.